Steve on Image Processing

August 22nd, 2006

Responses to reader challenge

Thanks to Kimo Johnson and Perttu Ranta-aho for responding to my custom spatial transformation challenge.

Contents

Kimo's submission

Kimo's custom transform turns the football image inside out!

im = imread('football.jpg');
sx = 1.47;
sy = 1.6;
c2 = 0.14;
c3 = 0.07;
p1 = 0.25;
p2 = 0.125;

f = @(x) complex(x(:,1)/sx,x(:,2)/sy);
g = @(z) c2*log(abs(z + p1)) + c2*log(abs(z - p1)) + ...
    c3*log(abs(z + p2*i)) + c3*log(abs(z - p2*i));
h = @(w) [real(w), imag(w)];
q = @(x, unused) h(g(f(x)));

tform = maketform('custom', 2, 2, [], q, []);
trans = imtransform(im, tform, 'UData', [-1 1], 'VData', [-1 1], ...
    'XData', [-1 1], 'YData', [-1 1]);

subplot(1,2,1)
imshow(im)
title('Original')

subplot(1,2,2)
imshow(trans)
title('Transformed')

Perttu's submission

I really don't know how to describe this one.

Notice how Perttu used the 'FillValues' option of imtransform to get the red pixels in the output.

I = imread('http://blogs.mathworks.com/images/steve/80/samu.jpg');

I'm going to shrink the image a bit so it's not too big for the blog page.

I = imresize(I, 0.5);
clf
imshow(I)
title('Cute kid!')
imcredit('Image courtesy of Perttu Ranta-aho')  % MATLAB Central File Exchange
f = @(x) complex(x(:,1),x(:,2));
g = @(z) ((z-1).*(z+1).*(z+.1-2*i).*(z+1+2*i)) ./ ...
    (power(z+1+i,4)+power(z-1-i,4));
h = @(w) [real(w) imag(w)];
q = @(x,unused) h(g(g(g(g(f(x))))));
tform = maketform('custom', 2, 2, [], q, []);
J=imtransform(I, tform, 'UData', [-1.5 1.5], 'VData', [-1.5 1.5], ...
    'XData', [0 6], 'YData', [-4 2], 'FillValues', [255 0 0]');
imshow(J)

Wow!


Get the MATLAB code

Published with MATLAB® 7.2

One Response to “Responses to reader challenge”

  1. Matthew Simoneau replied on :

    I know how to describe Perttu’s submission… ART!

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Steve Eddins manages the Image & Geospatial development team at The MathWorks and coauthored Digital Image Processing Using MATLAB. He writes here about image processing concepts, algorithm implementations, and MATLAB.

  • Sana: hi steve, could you explain to me how i would be able to use the dir function, to do a loop through a directory...
  • Nishtha: Sir, I have preprocessed the image in following steps: [1] adaptive histogram equalization [2] thresholding...
  • Kristof: I also strongly support the idea. I have just recently bumped into the problem that im2single was not...
  • Steve: David—I’ m glad you found it useful!
  • David Lalejini: I found your example very useful for finding connected nodes in a large set of input pairs. I start...
  • tommy: Dear Steve, I have a question,please if you are kind to help me regarding the accumulator array dimensions of...
  • Steve: Abc—I don’t know how to distinguish the faces. You might try posting your question in the MATLAB...
  • Manju: well if we have a few ovals within each other like in a cell how do we measure the distance from the center...
  • Steve: Manju—What do you mean? How is each region defined?
  • Manju: if we have 2-3 regions within each other how do we measure the regions of each one?

These postings are the author's and don't necessarily represent the opinions of The MathWorks.