How to display an image using given x coordinates(256*256) and y coordinates (256*256)

3 views (last 30 days)
I retrieved x and y coordinates of an RGB image (red, green and blue pixels matrices) and performed arithmetic operations on x and y coordinates matrices separately and displayed the new distorted image. In the second step, I performed all the above arithmetic operation in reverse and got the original x and y coordinates matrices separately. Please help me to display the original image using the recovered original x and y coordinates matrices.

Answers (3)

KSSV
KSSV on 2 Mar 2017
Read about surf, pcolor
If you have a 3D matrix, use imshow.

Image Analyst
Image Analyst on 2 Mar 2017
So you have x and y coordinates. They will be be in an N by 2 matrix, right? And then you did something to it to somehow alter the x and y coordinates, but it's still an N by 2 matrix, just with new x,y values in it. So are you wanting to take the new x,y coordinates and build a new color image where the pixel at the old x,y location now appears at the new x,y location? If so, simply use a for loop:
for k = 1 : numel(newX)
newRow = round(newY(k));
newCol = round(newX(k));
newRGB(newRow, newCol, :) = originalRGB(oldY(k), oldX(k), :);
end
imshow(newRGB);
If they're in a 256x256 matrix, like you used meshgrid to get them, then you can still use the above code.
  3 Comments
Image Analyst
Image Analyst on 2 Mar 2017
You forgot to attach C:\Users\nitin\Documents\MATLAB\tree.png.
Meanwhile I'm attaching my image scrambling demos.

Sign in to comment.


Guillaume
Guillaume on 2 Mar 2017
I believe I showed you how to get the image based on the coordinates in your previous question
scrambledimage = img(sub2ind(size(img), y1+1, x1+1)); %assuming your |x| and |y| are zero based.
You then simply imshow it:
imshow(scrambledimage);
  5 Comments
Shafali
Shafali on 2 Mar 2017
Sir, got the result.
pic1=sub2ind(size(scrambledimage), newy, newx);
unscrambled(pic) = scrambledimage(pic1); unscrambled=reshape(unscrambled,256,256);
Thanks for your guidance. I am really very thankful.
Partha Biswas
Partha Biswas on 11 Oct 2019
Edited: Image Analyst on 12 Oct 2019
I am trying the code below to unscramble. But it's not happening. Could you please help here? also please let me know what is pic in your code. I am using a 128*128 grayscale image.
f1 = floor((3 + 13 * x) / 128);
x1 = mod(3 + 13 * x, 128);
f2 = floor((5 + 7 * y) / 128);
y1 = mod(5 + 7 * y, 128);
newx = mod(((x1 + (f1 * 128)) - 3) / 13, 129);
newy = mod(((y1 + (f2 * 128)) - 5) / 7, 129);
pic1=sub2ind(size(scrambledimage), newy, newx);
unscrambled(pic) = scrambledimage(pic1);
unscrambled=reshape(unscrambled,128,128);

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!