Re: Image rotation and new image recreation



Thanks for your help. I guess my question then, is how do I go about doing that? Scanning the output image and doing bilinear interpolation to get the output values?

Thanks.



ImageAnalyst <imageanalyst@xxxxxxxxxxxxxx> wrote in message <816de1ed-780b-4583-8d54-e3ea216b36d2@xxxxxxxxxxxxxxxxxxxxxxxxxxx>...
On Jul 31, 11:42?am, "Rheena " <rheena.w...@xxxxxxxxx> wrote:
Hello,

I am trying to rotate a binary image over a specified angle theta and recreate it in Matlab. ?I&#8217;ve used the rotation matrix to find the coordinate locations of the new points, xnew and ynew from the original u and v values of the binary image. ?I then want to recreate the image using these xnew and ynew calculated values by transferring the intensity values from the original binary image of pixel (u,v) to these new points and call the new image rotated_image. ?I&#8217;ve used a for loop to run along the entire height and width of the image, and thought that by redefining the pixel values in the new image (rotated_image) to be equal to the x and y intensity values of the binary image, it would do the trick. ?The image returned, however, appears entirely black.
I&#8217;m not sure how to transfer/redefine pixel values/assign new intensity values for pixels to recreate a new image.

rotated_image = zeros(size(binaryimage));
?u = 1;
?v = 1;
for i = 1:width
? ?for j = 1:height
? ? ? ? matrix = [cos(theta) -sin(theta); sin(theta) cos(theta)];
? ? ? ? old_point = [u; v];
? ? ? ? new_point = matrix * old_point;
? ? ? ? xnew = round(new_point(1,:));
? ? ? ? ynew = round(new_point(2,:));
? ? ? ? ? ? ? ? if xnew < width && xnew > 0 && ynew < height && ynew > 0
? ? ? ? ? ? ? ? ? ? rotated_image(ynew,xnew) = binaryimage(round(v),round(u));
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? rotated_image(ynew,xnew) = 0;
? ? ? ? ? ? ? ? end

? ?end
end

imshow(rotated_image)

Thanks for your help.

------------------------------------------------------------------------------------
Rheena:
Two problems in your code.
1. Since you have a binary image, you should use imshow
(rotated_image, []). Otherwise it will display 0-255 as normal, and
how are you going to see a 1 gray level object on a 0 gray level
background? You can't - that's why it looks all black. Using []
scales it for display so that the 1 will get mapped to 255 and the 1
parts will now be visible.
2. You are scanning backwards. You should not scan the input image
and decide where to send input pixels. Doing that will leave some
output pixels with nothing assigned to them and will look like there
are holes or black dots in your output image. It's worse for some
angles than others. What you want to do is scan your output image and
decide where to pull your input pixel from. Chances are that this
will land somewhere in between input pixels so you will have to do
bilinear interpolation to figure out what the input image gray value
would be at that location if a pixel were located there. Then use
that as the output pixel value. If the input pixel location is
outside the input image, then of course you will leave that putput
pixel as 0 or whatever background (or unassigned) pixel value you want
to use.
Regards,
ImageAnalyst
.



Relevant Pages

  • Re: Questions about the Log Polar Transform.
    ... >transform maps radial lines in Cartesian space to horizontal lines in polar ... coordinates of the pixel in the source image. ... If you want a log-polar output image, not just a polar one, you'll also ...
    (sci.image.processing)
  • Re: Image rotation and new image recreation
    ... how are you going to see a 1 gray level object on a 0 gray level ... and decide where to send input pixels. ... output pixels with nothing assigned to them and will look like there ... would be at that location if a pixel were located there. ...
    (comp.soft-sys.matlab)
  • Re: Is there anyone who has developed map projection library?
    ... >To add a comment to Pauls thoughs on transformation of images: ... Now scan through the OUTPUT image and find ... >the location of this pixel in the original image and fill it with that value. ... >because your entire output image is filled with values (or outside the input image) ...
    (comp.infosystems.gis)
  • Re: Rookie having problems with some filter code. Any help?
    ... This doesn't seem to match your output image so perhaps you are adding the filter result to the input pixel value. ... with a 4 in the middle, this would be a Laplacian but now it is a sum of the Laplacian and the center pixel. ...
    (sci.image.processing)
  • Re: Image rotation and new image recreation
    ... Scan your output image row by row, ... pixel, decide where your input pixel should come from, then use ... bicubic or bilinear interpolation to get the value there (which most ...
    (comp.soft-sys.matlab)

Loading