Re: Image rotation and new image recreation
- From: "Rheena " <rheena.ware@xxxxxxxxx>
- Date: Thu, 6 Aug 2009 16:40:19 +0000 (UTC)
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’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’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’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
- Follow-Ups:
- Re: Image rotation and new image recreation
- From: ImageAnalyst
- Re: Image rotation and new image recreation
- References:
- Re: Image rotation and new image recreation
- From: ImageAnalyst
- Re: Image rotation and new image recreation
- Prev by Date: Re: How to define a local variable in nested function
- Next by Date: Re: how to assign filename?
- Previous by thread: Re: Image rotation and new image recreation
- Next by thread: Re: Image rotation and new image recreation
- Index(es):
Relevant Pages
|
Loading