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

조회 수: 3 (최근 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
Image Analyst
Image Analyst 2017년 3월 2일
You forgot to attach C:\Users\nitin\Documents\MATLAB\tree.png.
Meanwhile I'm attaching my image scrambling demos.

댓글을 달려면 로그인하십시오.


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