{"id":707,"date":"2012-11-27T07:00:06","date_gmt":"2012-11-27T12:00:06","guid":{"rendered":"https:\/\/blogs.mathworks.com\/steve\/?p=707"},"modified":"2019-11-01T09:05:37","modified_gmt":"2019-11-01T13:05:37","slug":"image-effects-part-3","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/steve\/2012\/11\/27\/image-effects-part-3\/","title":{"rendered":"Don&#8217;t Photoshop it&#8230;MATLAB it! Image Effects with MATLAB (Part 3)"},"content":{"rendered":"<div class=\"content\"><!--introduction--><p><i>I'd like to welcome back guest blogger <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/911\">Brett Shoelson<\/a> for the continuation of his series of posts on implementing image special effects in MATLAB. Brett, a contributor for the <a href=\"https:\/\/blogs.mathworks.com\/pick\/\">File Exchange Pick of the Week blog<\/a>, has been doing image processing with MATLAB for almost 20 years now.<\/i><\/p>\r\n\r\n<p>\r\n<a href=\"https:\/\/blogs.mathworks.com\/steve\/2012\/11\/13\/image-effects-part-1\/\">[Part 1]<\/a> \r\n<a href=\"https:\/\/blogs.mathworks.com\/steve\/2012\/11\/20\/image-effects-part-2\/\">[Part 2]<\/a>\r\n<a href=\"https:\/\/blogs.mathworks.com\/steve\/2012\/11\/27\/image-effects-part-3\/\">[Part 3]<\/a>\r\n<a href=\"https:\/\/blogs.mathworks.com\/steve\/2012\/12\/04\/image-effects-part-4\/\">[Part 4]<\/a>\r\n<\/p>\r\n\r\n\r\n<!--\/introduction--><h3>Contents<\/h3><div><ul><li><a href=\"#231758d1-cf0c-4c5d-8b94-af420c1cee7c\">Put Me In the Zoo!<\/a><\/li><li><a href=\"#f0a04ef4-e680-4e9b-a793-ff4c0fc01b09\"><tt>imfreehand<\/tt> to the Rescue!<\/a><\/li><li><a href=\"#ffef313f-58dc-43fe-ac88-f571a48cfa44\">Now to Color the Spots<\/a><\/li><li><a href=\"#36111bdf-8d1f-4693-bb38-f89deeba68bc\">Next Up: Out Standing in the Field<\/a><\/li><\/ul><\/div><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/DecorrstretchedElephant.png\" alt=\"\"> <\/p><h4>Put Me In the Zoo!<a name=\"231758d1-cf0c-4c5d-8b94-af420c1cee7c\"><\/a><\/h4><p>So far (<a href=\"https:\/\/blogs.mathworks.com\/steve\/?p=701\">post 1<\/a>, <a href=\"https:\/\/blogs.mathworks.com\/steve\/?p=704\">post 2<\/a>) in this guest series on creating special image effects with MATLAB, I've applied processes to the entire image. For instance, I created the image above by starting with the contrast-enhanced elephant from my previous post. I created the pseudocolor effect by decorrelation-stretching (using <a href=\"https:\/\/www.mathworks.com\/help\/images\/ref\/decorrstretch.html\"><tt>decorrstretch<\/tt><\/a>) the resulting image. And then I enhanced the colors a bit using <tt>imadjust<\/tt>.<\/p><pre class=\"language-matlab\">URL = <span class=\"string\">'https:\/\/blogs.mathworks.com\/pick\/files\/ElephantProfile.jpg'<\/span>;\r\nimg = imread(URL);\r\ncolorElephant = decorrstretch(img);\r\ncolorElephant = imadjust(colorElephant,[0.10; 0.79],[0.00; 1.00], 1.10);\r\n<\/pre><p>(Decorrelation stretching is useful for visualizing, and sometimes analyzing, imagery by reducing inter-plane autocorrelation levels in an image. It is often used with multispectral or hyperspectral images.)<\/p><p>In this installment, I wanted to take an ordinary photograph of a giraffe and modify it to give the giraffe something out-of-the-ordinary. But to do so, I needed to <i>segment<\/i> the image--to create a binary mask with 1's in the locations of my regions of interest, and 0's elsewhere. There are <i>many<\/i> approaches to segmenting images--indeed, there are many approaches in the <a href=\"https:\/\/www.mathworks.com\/products\/image\/\">Image Processing Toolbox<\/a>. So if we wanted to color the spots of a giraffe, for instance, we'd first have to find an appropriate method of segmenting the spots. (Without a doubt, getting a good segmentation is the most difficult part of many image processing problems!)<\/p><p>First, let's read and adjust the image of the giraffe.<\/p><pre class=\"language-matlab\">URL = <span class=\"string\">'https:\/\/blogs.mathworks.com\/pick\/files\/GiraffeProfile.jpg'<\/span>;\r\nimg = im2double(imread(URL));\r\nimg = imadjust(img,[0.20; 0.80],[0.00; 0.80], 1.10);\r\nhAx = axes; <span class=\"comment\">%Notice that I created a handle to the axes; I will use that later.<\/span>\r\nimshow(img);\r\n<\/pre><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/OriginalGiraffe.png\" alt=\"\"> <\/p><p>Next, I want to segment the giraffe's spots. Usually (but not always), when I'm trying to segment an RGB image, I find I can get a good mask working with one (or sometimes multiple) grayscale representation(s) of the color images. I like to look at the individual colorplanes and at different colorspace representations of the image as well. <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/19-delta-sigma-toolbox-explorergb\"><tt>ExploreRGB<\/tt><\/a> makes that exploration easy:<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/ExploreRGB.png\" alt=\"\"> <\/p><p>As we can see in this image of the ExploreRGB GUI, the giraffe's spots are fairly well segmented for us in the \"saturation\" plane of the HSV colorspace. So let's start there for our segmentation of the spots.<\/p><pre>grayImg = rgb2hsv(img);\r\ngrayImg = grayImg(:,:,2);\r\ngrayImg =  imadjust(grayImg,[0.6; 1.0],[0.00; 1.00], 1.00);\r\nspotMask = im2bw(grayImg,graythresh(grayImg));<\/pre><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/GiraffesInProgress.png\" alt=\"\"> <\/p><p>Now, if I were happy with that as a segmentation mask, I could move on. But I only wanted the giraffe's spots--not its head or mane. I could continue to try different programmatic approaches; remember that I can combine these logical masks in any way that makes sense. But instead, I'm going to take my first cue from Photoshop and go old-school: I'm going to manually exclude the portions of the giraffe that I don't want to colorize. So how do I do that?<\/p><h4><tt>imfreehand<\/tt> to the Rescue!<a name=\"f0a04ef4-e680-4e9b-a793-ff4c0fc01b09\"><\/a><\/h4><p>A few years back (R2008a, I believe), we refactored our region-of-interest (ROI) tools. I want to draw a freehand region, and use it to help mask my image. So, using <a href=\"https:\/\/www.mathworks.com\/help\/images\/ref\/imfreehand.html\"><tt>imfreehand<\/tt><\/a>, I quickly encircle the region I want to exclude. (I say \"quickly,\" but you generally want to take your time with this step; getting a good segmentation mask is crucial to getting a good effect!)<\/p><p>To create the manual mask:<\/p><pre class=\"language-matlab\">manualMask = imfreehand;\r\nposns = getPosition(manualMask);\r\n[m,n,~] = size(grayImg);\r\nexcludeMask = poly2mask(posns(:,1),posns(:,2),m,n);\r\n<\/pre><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/GiraffesInProgress2.png\" alt=\"\"> <\/p><p>Now I can combine that with my original spot mask, with the logical combination \"...AND NOT....\":<\/p><pre class=\"language-matlab\">spotMask  = spotMask &amp; ~excludeMask;\r\n<\/pre><p>In displaying the result (below left), I recognize that I trimmed the mask manually a bit tighter than I intended, so I will dilate it a bit (<a href=\"https:\/\/www.mathworks.com\/help\/images\/ref\/imdilate.html\"><tt>imdilate<\/tt><\/a>), and then exclude small regions (fewer than 10 connected pixels) using <a href=\"https:\/\/www.mathworks.com\/help\/images\/ref\/bwareaopen.html\"><tt>bwareaopen<\/tt><\/a>. The result is shown below on the right.<\/p><pre class=\"language-matlab\">spotMask  = spotMask &amp; imdilate(~excludeMask,strel(<span class=\"string\">'disk'<\/span>,2));\r\nspotMask = bwareaopen(spotMask,10);\r\n<\/pre><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/GiraffesInProgress3.png\" alt=\"\"> <\/p><p>That's close to my desired mask, but I'm going to tweak it a bit more by filling holes in the spots (<a href=\"https:\/\/www.mathworks.com\/help\/images\/ref\/imfill.html\"><tt>imfill<\/tt><\/a>) and by manipulating it with some morphological operations (<a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/23697-image-morphology\">MorphTool<\/a> again!). One more application of <tt>bwareaopen<\/tt> (this time, keeping only very large blobs), and I have the segmentation mask looking the way I want it.<\/p><pre>spotMask = imfill(spotMask,'holes');\r\nspotMask = imopen(spotMask,strel('disk',10));\r\nspotMask = imdilate(spotMask,strel('disk',10));\r\nspotMask = bwareaopen(spotMask,2000);<\/pre><h4>Now to Color the Spots<a name=\"ffef313f-58dc-43fe-ac88-f571a48cfa44\"><\/a><\/h4><p>From this point, coloring the spots was reasonably straightforward: I simply labeled the spots (<a href=\"https:\/\/www.mathworks.com\/help\/images\/ref\/bwlabel.html\"><tt>bwlabel<\/tt><\/a>) and colored the labeled regions by calling <a href=\"https:\/\/www.mathworks.com\/help\/images\/ref\/label2rgb.html\"><tt>label2rgb<\/tt><\/a>. (Also, I specified \"jet\" as my <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/colormap.html\">colormap<\/a> and used the \"shuffle\" command to randomly assign map colors to the spots.) Next, I set the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012b\/matlab\/ref\/hold.html\">\"hold\"<\/a> property of the current axes (i.e., the one containing the original color image), and displayed the colored spots on top of the original image. Finally, I modified the \"alphadata\" property of the colored-spot image to set its transparency to 0.25.<\/p><pre class=\"language-matlab\">L = bwlabel(spotMask);\r\ncolormask = label2rgb(L,jet(max(L(:))),[0 0 0],<span class=\"string\">'shuffle'<\/span>);\r\n<span class=\"comment\">% Using the handle to the axes that contains the original image, make<\/span>\r\n<span class=\"comment\">% that axes current, and set its \"hold\" property on.<\/span>\r\naxes(hAx)\r\nhold <span class=\"string\">on<\/span>\r\nh = imshow(colormask); <span class=\"comment\">%I created a handle here, too.<\/span>\r\ncolortrans = 0.25;\r\nset(h,<span class=\"string\">'alphadata'<\/span>,colortrans);\r\n<\/pre><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/GiraffesInProgress4.png\" alt=\"\"> <\/p><p>Now all that remains is to capture the visualization as an RGB image. I'm simply going to start with a copy of the original giraffe image, and modify it colorplane-by-colorplane, scaling each by 0.75 (i.e., 1-colortrans) and adding the scaled RGB components of the colored-spot image:<\/p><pre class=\"language-matlab\">imgEnhanced = img;\r\n<span class=\"keyword\">for<\/span> ii = 1:3\r\n   imgEnhanced(:,:,ii) = img(:,:,ii)*(1-colortrans) + im2double(colormask(:,:,ii))*colortrans;\r\n<span class=\"keyword\">end<\/span>\r\n<\/pre><h4>Next Up: Out Standing in the Field<a name=\"36111bdf-8d1f-4693-bb38-f89deeba68bc\"><\/a><\/h4><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/zebrainpastelfield.png\" alt=\"\"> <\/p><p>All images copyright Brett Shoelson; used with permission.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_74a503e6660b4044b1889387d9c49a9f() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='74a503e6660b4044b1889387d9c49a9f ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 74a503e6660b4044b1889387d9c49a9f';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        copyright = 'Copyright 2012 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }   \r\n     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_74a503e6660b4044b1889387d9c49a9f()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2012b<br><\/p><p class=\"footer\"><br>\r\n      Published with MATLAB&reg; R2012b<br><\/p><\/div><!--\r\n74a503e6660b4044b1889387d9c49a9f ##### SOURCE BEGIN #####\r\n%% Don't Photoshop it...MATLAB it! Image Effects with MATLAB (Part 3)\r\n%\r\n% _I'd like to welcome back guest blogger\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/911 Brett\r\n% Shoelson> for the continuation of his series of posts on implementing\r\n% image special effects in MATLAB. Brett, a contributor for the\r\n% <https:\/\/blogs.mathworks.com\/pick\/ File Exchange Pick of the Week blog>,\r\n% has been doing image processing with MATLAB for almost 20 years now._\r\n%%\r\n% \r\n% <<https:\/\/blogs.mathworks.com\/pick\/files\/DecorrstretchedElephant.png>>\r\n% \r\n\r\n%% Put Me In the Zoo!\r\n% So far (<https:\/\/blogs.mathworks.com\/steve\/?p=701 post 1>,\r\n% <https:\/\/blogs.mathworks.com\/steve\/?p=704 post 2>) in this guest series on\r\n% creating special image effects with MATLAB, I've applied processes to the\r\n% entire image. For instance, I created the image above by starting with\r\n% the contrast-enhanced elephant from my previous post. I created the\r\n% pseudocolor effect by decorrelation-stretching (using\r\n% <https:\/\/www.mathworks.com\/help\/images\/ref\/decorrstretch.html\r\n% |decorrstretch|>) the resulting image. And then I enhanced the colors a\r\n% bit using |imadjust|.\r\n%\r\n%   URL = 'https:\/\/blogs.mathworks.com\/pick\/files\/ElephantProfile.jpg';\r\n%   img = imread(URL);\r\n%   colorElephant = decorrstretch(img);\r\n%   colorElephant = imadjust(colorElephant,[0.10; 0.79],[0.00; 1.00], 1.10);\r\n\r\n%%\r\n% (Decorrelation stretching is useful for visualizing, and sometimes\r\n% analyzing, imagery by reducing inter-plane autocorrelation levels in an\r\n% image. It is often used with multispectral or hyperspectral images.)\r\n\r\n%%\r\n% In this installment, I wanted to take an ordinary photograph of a giraffe and\r\n% modify it to give the giraffe something out-of-the-ordinary. But to do\r\n% so, I needed to _segment_ the imageREPLACE_WITH_DASH_DASHto create a binary mask with 1's\r\n% in the locations of my regions of interest, and 0's elsewhere. There are\r\n% _many_ approaches to segmenting imagesREPLACE_WITH_DASH_DASHindeed, there are many approaches\r\n% in the <https:\/\/www.mathworks.com\/products\/image\/ Image Processing Toolbox>.\r\n% So if we wanted to color the spots of a giraffe, for instance, we'd first have\r\n% to find an appropriate method of segmenting the spots. (Without a doubt, getting a\r\n% good segmentation is the most difficult part of many image processing problems!) \r\n\r\n%% \r\n% First, let's read and adjust the image of the giraffe. \r\n\r\n%%\r\n%   URL = 'https:\/\/blogs.mathworks.com\/pick\/files\/GiraffeProfile.jpg';\r\n%   img = im2double(imread(URL));\r\n%   img = imadjust(img,[0.20; 0.80],[0.00; 0.80], 1.10);\r\n%   hAx = axes; %Notice that I created a handle to the axes; I will use that later.\r\n%   imshow(img); \r\n\r\n%%\r\n% \r\n% <<https:\/\/blogs.mathworks.com\/pick\/files\/OriginalGiraffe.png>>\r\n% \r\n\r\n%%\r\n% Next, I want to segment the giraffe's spots. Usually (but not always),\r\n% when I'm trying to segment an RGB image, I find I can get a good\r\n% mask working with one (or sometimes multiple) grayscale\r\n% representation(s) of the color images. I like to look at the individual\r\n% colorplanes and at different colorspace representations of the image as\r\n% well. <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/19-delta-sigma-toolbox-explorergb |ExploreRGB|>\r\n% makes that exploration easy:\r\n\r\n%%\r\n% \r\n% <<https:\/\/blogs.mathworks.com\/pick\/files\/ExploreRGB.png>>\r\n% \r\n\r\n%%\r\n% As we can see in this image of the ExploreRGB GUI, the\r\n% giraffe's spots are fairly well segmented for us in the \"saturation\"\r\n% plane of the HSV colorspace. So let's start there for our segmentation of\r\n% the spots.\r\n\r\n%%\r\n%  grayImg = rgb2hsv(img);\r\n%  grayImg = grayImg(:,:,2);\r\n%  grayImg =  imadjust(grayImg,[0.6; 1.0],[0.00; 1.00], 1.00);\r\n%  spotMask = im2bw(grayImg,graythresh(grayImg));\r\n\r\n%%\r\n% \r\n% <<https:\/\/blogs.mathworks.com\/pick\/files\/GiraffesInProgress.png>>\r\n% \r\n\r\n%%\r\n% Now, if I were happy with that as a segmentation mask, I could move on.\r\n% But I only wanted the giraffe's spotsREPLACE_WITH_DASH_DASHnot its head or mane. I could\r\n% continue to try different programmatic approaches; remember that I can\r\n% combine these logical masks in any way that makes sense. But instead, I'm\r\n% going to take my first cue from Photoshop and go old-school: I'm going to\r\n% manually exclude the portions of the giraffe that I don't want to\r\n% colorize. So how do I do that?\r\n\r\n%% |imfreehand| to the Rescue!\r\n% A few years back (R2008a, I believe), we refactored our\r\n% region-of-interest (ROI) tools. I want to draw a freehand region, and use\r\n% it to help mask my image. So, using\r\n% <https:\/\/www.mathworks.com\/help\/images\/ref\/imfreehand.html |imfreehand|>,\r\n% I quickly encircle the region I want to exclude. (I say \"quickly,\" but\r\n% you generally want to take your time with this step; getting a good\r\n% segmentation mask is crucial to getting a good effect!)\r\n%\r\n%%\r\n% To create the manual mask:\r\n%\r\n%   manualMask = imfreehand;\r\n%   posns = getPosition(manualMask);\r\n%   [m,n,~] = size(grayImg);\r\n%   excludeMask = poly2mask(posns(:,1),posns(:,2),m,n);\r\n%%\r\n% \r\n% <<https:\/\/blogs.mathworks.com\/pick\/files\/GiraffesInProgress2.png>>\r\n% \r\n%%\r\n% Now I can combine that with my original spot mask, with the logical\r\n% combination \"...AND NOT....\": \r\n%\r\n%   spotMask  = spotMask & ~excludeMask;\r\n\r\n%%\r\n% In displaying the result (below left), I recognize that\r\n% I trimmed the mask manually a bit tighter than I intended, so I will\r\n% dilate it a bit (<https:\/\/www.mathworks.com\/help\/images\/ref\/imdilate.html |imdilate|>), and then exclude small regions (fewer than 10 connected\r\n% pixels) using\r\n% <https:\/\/www.mathworks.com\/help\/images\/ref\/bwareaopen.html |bwareaopen|>.\r\n% The result is shown below on the right.\r\n%\r\n%   spotMask  = spotMask & imdilate(~excludeMask,strel('disk',2));\r\n%   spotMask = bwareaopen(spotMask,10);\r\n\r\n%%\r\n%\r\n% <<https:\/\/blogs.mathworks.com\/pick\/files\/GiraffesInProgress3.png>>\r\n% \r\n%%\r\n% That's close to my desired mask, but I'm going to tweak it a bit more by filling \r\n% holes in the spots (<https:\/\/www.mathworks.com\/help\/images\/ref\/imfill.html |imfill|>) \r\n% and by manipulating it with some morphological operations\r\n% (<https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/23697-image-morphology MorphTool> again!).\r\n% One more application of |bwareaopen| (this time, keeping only very large blobs), and I\r\n% have the segmentation mask looking the way I want it.\r\n%\r\n%  spotMask = imfill(spotMask,'holes');\r\n%  spotMask = imopen(spotMask,strel('disk',10));\r\n%  spotMask = imdilate(spotMask,strel('disk',10));\r\n%  spotMask = bwareaopen(spotMask,2000);\r\n\r\n%% Now to Color the Spots\r\n% From this point, coloring the spots was reasonably straightforward: I\r\n% simply labeled the spots\r\n% (<https:\/\/www.mathworks.com\/help\/images\/ref\/bwlabel.html |bwlabel|>)\r\n% and colored the labeled regions by calling\r\n% <https:\/\/www.mathworks.com\/help\/images\/ref\/label2rgb.html |label2rgb|>.\r\n% (Also, I specified \"jet\" as my <https:\/\/www.mathworks.com\/help\/matlab\/ref\/colormap.html colormap>\r\n% and used the \"shuffle\" command to randomly assign map colors to the\r\n% spots.) Next, I set the\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2012b\/matlab\/ref\/hold.html \"hold\"> property \r\n% of the current axes (i.e., the one containing the original color image), and displayed\r\n% the colored spots on top of the original image. Finally, I modified the\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/image_props.html \"alphadata\">\r\n% property of the colored-spot image to set its transparency to 0.25.\r\n\r\n%%\r\n%   L = bwlabel(spotMask);\r\n%   colormask = label2rgb(L,jet(max(L(:))),[0 0 0],'shuffle');\r\n%   % Using the handle to the axes that contains the original image, make\r\n%   % that axes current, and set its \"hold\" property on.\r\n%   axes(hAx)\r\n%   hold on\r\n%   h = imshow(colormask); %I created a handle here, too.\r\n%   colortrans = 0.25;\r\n%   set(h,'alphadata',colortrans);\r\n%%\r\n% \r\n% <<https:\/\/blogs.mathworks.com\/pick\/files\/GiraffesInProgress4.png>>\r\n% \r\n\r\n%%\r\n% Now all that remains is to capture the visualization as an RGB image. I'm\r\n% simply going to start with a copy of the original giraffe image, and\r\n% modify it colorplane-by-colorplane, scaling each by 0.75 (i.e.,\r\n% 1-colortrans) and adding the scaled RGB components of the colored-spot image: \r\n%\r\n%   imgEnhanced = img;\r\n%   for ii = 1:3\r\n%      imgEnhanced(:,:,ii) = img(:,:,ii)*(1-colortrans) + im2double(colormask(:,:,ii))*colortrans;\r\n%   end\r\n\r\n%% Next Up: Out Standing in the Field\r\n%%\r\n% \r\n% <<https:\/\/blogs.mathworks.com\/pick\/files\/zebrainpastelfield.png>>\r\n% \r\n%%\r\n% All images copyright Brett Shoelson; used with permission.\r\n\r\n##### SOURCE END ##### 74a503e6660b4044b1889387d9c49a9f\r\n-->","protected":false},"excerpt":{"rendered":"<!--introduction--><p><i>I'd like to welcome back guest blogger <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/911\">Brett Shoelson<\/a> for the continuation of his series of posts on implementing image special effects in MATLAB. Brett, a contributor for the <a href=\"https:\/\/blogs.mathworks.com\/pick\/\">File Exchange Pick of the Week blog<\/a>, has been doing image processing with MATLAB for almost 20 years now.<\/i>... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/steve\/2012\/11\/27\/image-effects-part-3\/\">read more >><\/a><\/p>","protected":false},"author":42,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[22],"tags":[595,138,166,537,727,82,90,84,390,949,124,136,416,108,76,36,276,152,296,957,190,106],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/707"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/users\/42"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/comments?post=707"}],"version-history":[{"count":8,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/707\/revisions"}],"predecessor-version":[{"id":2374,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/707\/revisions\/2374"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media?parent=707"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/categories?post=707"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/tags?post=707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}