Issue with using imrotate to determine the location of a pixle after rotating an image
4 views (last 30 days)
Show older comments
Hello,
I am trying to simply rotate an array by some angle theta, and then determine the location of one particular value after rotation. I started out by imaging a 1024 by 1024 array. Then I used [a,b] = guinput(1) to pick a point on the image. Next I rotated my image by some random angle. Now I want to find the location of the pixel I choose previously on my newly rotated image. For this I simply produced a 1024 by 1024 matrix "Z" of zeros and set the point Z(a,b) = 1. I used the same imrotate(Z,theta) to rotate my zero's matrix, and I used find(rotated Z == 1) to find the location of rotated pixel. However, this does not work all the time. Every so often, when I rotate my zeros matrix, the pixel with a value of 1 disappears. I am lost to why this occurs, and how to prevent this from occurring. If anyone can give me a little insight onto how to correct for this I would be very appreciative.
Thanks, Eric
0 Comments
Accepted Answer
Image Analyst
on 27 Nov 2012
I don't see why this would not work. Are you saying that you clicked a point and made that point white, then rotated the image by some angle, and then that point vanished? The white pixel is nowhere to be found? I can see your test failing if you use bilinear or bicubic because that would change the value of the 1 to something less. But if you use the default, which is 'nearest' neighbor, then the one should retain it's exact value. The only thing I can think of is that it's slightly less due to digitization error, so try checking if it's close to 1, like abs(rotatedZ - 1) < 0.001 or something like that.
3 Comments
Image Analyst
on 27 Nov 2012
I believe the reason this is happening is that the output image is scanned to figure out where the input pixel should come from. You need to do it this way to avoid "holes" in the output image. If you do it the other way - send every input pixel to an output pixel - because of quantization error, sometimes two pixels will get sent to the same output pixel, and sometimes an output pixel will never get an input pixel assigned to it, which gives rise to the holes (unassigned pixels). You happened to pick a pixel that was never pulled over to the output image. If you pick a different method, like bilinear, then you will get it partially pulled over but it will be spread among 4 output pixels, so it will have a value less than it. Did that explain it well?
More Answers (0)
See Also
Categories
Find more on Geometric Transformation and Image Registration in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!