How to display an image using given x coordinates(256*256) and y coordinates (256*256)
2 次查看(过去 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.
0 个评论
回答(3 个)
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
2017-3-2
You forgot to attach C:\Users\nitin\Documents\MATLAB\tree.png.
Meanwhile I'm attaching my image scrambling demos.
Guillaume
2017-3-2
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 个评论
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!