How to display an image using given x coordinates(256*256) and y coordinates (256*256)
    4 views (last 30 days)
  
       Show older comments
    
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.
0 Comments
Answers (3)
  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
      
      
 on 2 Mar 2017
				You forgot to attach C:\Users\nitin\Documents\MATLAB\tree.png.
Meanwhile I'm attaching my image scrambling demos.
  Guillaume
      
      
 on 2 Mar 2017
        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
  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);
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


