0

I'm a beginner in matlab and I'm trying to transform a photo according to a function given in the code. My aim is to see where some points of the R^2 plan go. For example, i'd like to transform :

enter image description here

But I can't figure this out. I found some good conversations on this topic:

https://www.mathworks.com/matlabcentral/answers/81975-is-it-possible-to-pass-an-image-as-an-input-to-a-function-in-matlab

and good functions like :

https://www.mathworks.com/help/images/ref/imtransform.html

https://www.mathworks.com/help/images/ref/imwarp.html

but I don't understand what to do with that because I don't have a matrix but just like the function "1/z"...

The aim is to do something better than this :

How to plot the Wolfram Alpha grid? [MATLAB]

I've tried to add colors to the mesh graph but I ve not succed in doing so... I could only find how to change uniformly the colors, like setting all in green...

If you have another solution not using an image but constructing a grid of a range of colors and then deforming it (like in the link) or even better, instead of a grid, creating a whole plan with an uniform distribution of the colors... it also fixes the problem!

Thank you !

Marine Galantin
  • 1,634
  • 1
  • 17
  • 28

1 Answers1

1

You can use the surf function to plot a grid with colored patches. If you use the same code in my answer to your previous question, you could visualize the original grid with colors as follows:

C = X.^2 + Y.^2; %change this to any function you like to get different color patterns
surf(X,Y,C);
view([0, 90]); %view the mesh from above

Now, if you want to see how the transformed mesh looks like, you can do:

surf(U,V,C);
view([0, 90]);

where U and V are computed according to my previous answer.

Edit: Added sample code for transforming an image using geometricTransform2d and imwarp.

clear
clc

A = imread('peppers.png');

figure(1)
imshow(A)

t1 = geometricTransform2d(@ftransform);

Rin = imref2d(size(A),[-1 1],[-1 1]);
Rout = imref2d(size(A),[-5 5],[-5 5]);

B = imwarp(A, Rin, t1,'OutputView',Rout);
figure(2);
imshow(B)


function Xt = ftransform(X)

Z = complex(X(:,1),X(:,2));
Zt = 1./Z;
Xt(:,1) = real(Zt);
Xt(:,2) = imag(Zt);

end
Savithru
  • 735
  • 6
  • 12
  • actually I found the structure you're using. But the thing is I don't know what is the function of the color grid I see above... – Marine Galantin Dec 01 '18 at 17:56
  • 1
    I also found [this link](https://www.mathworks.com/help/images/exploring-a-conformal-mapping.html) which shows how conformal mappings can be applied to images in MATLAB. I think following the steps there should give you what you need. – Savithru Dec 01 '18 at 21:45
  • thank you for your help. I'll use what you already wrote here. I can't make a working example with the link you shared. It looks really interesting but I don't understand how to use the code they are writing... if you have the time maybe you can write a small working example with what they said? – Marine Galantin Dec 09 '18 at 14:06
  • 1
    See my updated answer. It turns out that the `imtransform` function they have used in the link is not recommended now. They suggest using `imwarp` instead, so I have used that in my answer. – Savithru Dec 09 '18 at 18:34