Don’t Photoshop it … MATLAB it! Image Effects with MATLAB (Part 1)
I'd like to introduce guest blogger Brett Shoelson, who has prepared a series of posts on implementing image special effects in MATLAB. Brett, a contributor for the File Exchange Pick of the Week blog, has been doing image processing with MATLAB for almost 20 years now.
[Part 1] [Part 2] [Part 3] [Part 4]
A Milestone, and a New Camera
My wife and kids and I recently returned from celebrating a milestone birthday--I'll not say which milestone!--in Namibia, where we spent a couple of weeks on Safari in Etosha National Park. The morning we were scheduled to leave the US, I began kicking myself: I simply couldn't make this trip without having a better camera. (I had been passionate about photography many years ago, but have more recently satisfied myself with snapshots from a small digital point-and-shoot camera.) So hours before our intercontinental flight, I found myself camera-shopping in a big-box electronics store, and after some deliberation, coming home with a new Nikon D5100 and a 55-300mm zoom lens.
Our trip was truly memorable--due in no small part to the 1200 photographs I took in the course of the vacation.
Yes, 1200 pictures. That's a lot of pictures--that I knew no one, including myself, would ever want to wade through. So while I was snapping away, capturing images just like the ones the cameras clicking to my left and right were capturing, I hatched a plan: I would create and share a small gallery of safari images set apart by the special effects I was designing for them in my head.
A Challenge: Use MATLAB to Create a Gallery of Safari Effects
Special effects--that's Photoshop's wheelhouse, right? In fact, I have a rarely-used license for Adobe's flagship product, and it made sense that this project would have me dusting it off. But here's the rub: I am a dyed-in-the-wool MATLABber--one who spends a lot of time helping customers tackle their image processing challenges using MATLAB and the Image Processing Toolbox. Could I implement these effects in MATLAB? What challenges would I face? And how could I overcome them?
It always rankles me just a bit when I hear people ask me--_knowing_ my penchant for processing images with MATLAB--to "Photoshop" an image for them. No, I won't Photoshop it for you. But I wil MATLAB it for you! So, new goal: Create a gallery of special effects for my safari photos using only MATLAB (and Toolboxes, of course!) , and blog about the experience. And before I get a flood of emails, let me point out that I know that this is not what MATLAB is about, and that it makes more sense to do artistic image manipulations using a special-effects-oriented tool. But I liked the challenge that doing it in MATLAB afforded. And I liked the opportunity to create (and share) more broadly useful tools that helped me achieve my goals.
First up: what do we get for free?
This image was relatively easy to create. (That's what I mean by getting the effect "for free.") I've used entropy filtering several times in the past; when I've needed to quantify the local orderedness or randomness of an image, I think of entropy filtering. The Toolbox function entropyfilt makes doing so simple. But I've also noticed that when you apply the function to an RGB image, sometimes the results are visually arresting. For example, using the mandrill image that ships with MATLAB, we can easily produce an interesting effect:
load mandrill img = ind2rgb(X,map); subplot(1,2,1);imshow(img); enhanced = entropyfilt(img,getnhood(strel('disk',1))); enhanced = enhanced/max(enhanced(:)); enhanced = imadjust(enhanced,stretchlim(enhanced)); subplot(1,2,2);imshow(enhanced);
Beyond the simple application of entropy filtering to an RGB image (and division by the maximum intensity of the image), I should address two other important aspects of that code block. First, notice that I specified a neigborhood using a disc-shaped structuring element (strel) of radius 1. And after the division by the maximum intensity, I modified the intensity mapping to enhance colors in the image using the imadjust function. So how did I select that structuring element? And how could improve the imadjust-mediate enhancement using non-default input parameters?
Two GUI Tools to Manage the Manipulations
To answer the first question, allow me to chat briefly about MorphTool, an interactive GUI I shared on the MATLAB Central File Exchange. MorphTool provides an interface for trying out different combinations of morphological operators and different shapes and sizes of structuring elements. So after I read in the image, I called it up in MorphTool, selected "entropy filtering," and changed the structuring element until I got the results I was after:
(MorphTool is available for free download, and if you are using R2012b, you can even install it in your Apps Tab.)
To answer the second question, I should point out that I also uploaded a file to the File Exchange many years ago (long before I was a MathWorker) that allowed interactive manipulation of the inputs to imadjust. I recently took that down--it was old and poorly implemented--and replaced it with another new GUI that is much more robust, better implemented, and also convertable to an App.
So, quite simply, I loaded the morphologically altered images of the mandrill and the zebras into ImadjustGUI and started playing with sliders until I got the desired results. Then I pressed the "Export" button, and got auto-generated code that generate those results:
To create the stylized image of the two zebras above:
URL = 'https://blogs.mathworks.com/pick/files/TwoZebras.jpg'; img = imread(URL); imgEnhanced = entropyfilt(img,getnhood(strel('Disk',4))); imgEnhanced = imgEnhanced/max(imgEnhanced(:)); imgEnhanced = imadjust(imgEnhanced,[0.30; 0.85],[0.90; 0.00], 0.90); imshow(imgEnhanced)
Steve was kind enough to allow me to share my experiences in his blog. In my next guest post, I'll step up the complexity a bit...working my way up to the zebra in the field, at the top of this post!
Next Up: Andy Warhol Meets an Elephant
All images except "mandrill" copyright Brett Shoelson; used with permission.
댓글을 남기려면 링크 를 클릭하여 MathWorks 계정에 로그인하거나 계정을 새로 만드십시오.