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

6 次查看(过去 30 天)
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.

回答(3 个)

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

Image Analyst
Image Analyst 2017-3-2
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 个评论

请先登录,再进行评论。


Guillaume
Guillaume 2017-3-2
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 个评论
Shafali
Shafali 2017-3-2
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 2019-10-11
编辑:Image Analyst 2019-10-12
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);

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by