Steve Eddins is a software development manager in the MATLAB and image processing areas at MathWorks. Steve coauthored Digital Image Processing Using MATLAB. He writes here about image processing concepts, algorithm implementations, and MATLAB.

I'd like to introduce Brett Shoelson as guest blogger for today. Many of you already know Brett from his work on the File Exchange Pick of the Week blog, or his posts on the comp.soft-sys.matlab newsgroup, or from his many presentations given on the road. I met Brett "virtually" many years ago, long before he came
to work for MathWorks, through his posts on the newsgroup. Brett's been doing fun, interesting, and even useful things to
images using MATLAB for quite a long time.

A few weeks ago Brett posted the Two Amigos Challenge on the Pick of the Week blog. Readers of the blog know that long-time contributor Bob Bemis (Hi, Bob!) has moved on from
MathWorks and isn't posting there anymore. Brett challenged his readers to digitally retouch the "Three Amigos" picture on
the blog and turn it into a "Two Amigos" picture using only MathWorks products.

I was so impressed with Brett's own solution to the Challenge that I invited him to show it to my readers here.

So here is Brett's solution to the Two Amigos Challenge ...

... in which we remove a subject from a photograph, and digitally retouch it to conceal the modification...

One more bit of cleanup:

Final result

Soften the edges: we can soften those edges a bit by applying locally an averaging filter where the (dilated) outline is logically
true:

H = fspecial('average');
% Roifilt2 is a 2-D filter. We can use it on RGB images, but we have to% operate plane-by-plane. But first, it's good practice to preallocate the% final matrix:
FINAL = zeros(size(rgb),'uint8');
for ii = 1:3
FINAL(:,:,ii) = roifilt2(H,rgb(:,:,ii),brettJiroEdge);
end
FINAL = imcrop(FINAL,[58 90 691 471]);
togglefig('Final Result')
imshow(FINAL)
% et voila!

13 CommentsOldest to Newest

I was recently surprised to find out that there seems to be nothing for dehazing/defogging on matlab central. Google comes up with things like a 2009 publication called “Single Image Dehazing” by Raanan Fattal, but I can’t find any simple matlab procedure for it. I’ve tried playing with histogram stretching/equalization, but it doesn’t seem to do it for my image. Can you make be show us how to remove the fog from the background of the original image in this blog? Thanks

There is one problem that still bothers me. The luminescence of the two amigos does not fit the much darker background. You should find a way to make the amigos darker and then the results will be perfect.

@Johnny,
I might have used a fill flash to brighten the foreground subjects, right? :)

Your point is valid, though. I might have improved the results if I had used the IMADJUST function:

%
J = imadjust(I,[low_in; high_in],[low_out; high_out])
%

operating individually on the R,G, and B colorplanes of the masked original image before concatenating them into |rgb|. That would let me easily map low_R in the original to low_R in the background, etc.