|
"Aleks" <ao2z@removeVirginia.edu> wrote in message <gtq37o$ans$1@fred.mathworks.com>...
> Hi everyone,
> I posted about this problem but I didn't get anywhere.
> the problem I have at hand is to rotate an image. The tricky part is that I don't want any new pixels to be created. For example: image I is 100x100 white image [I(:, :, 3) = 255]; J = imrotate(I, 45, 'crop'); The final result will be an 100x100 image with some black pixels. If I use the 'loose' option, I preserve all my white pixels but black pixels still get introduced to the image. This wouldn't be a problem since what I want are the white pixels however there are times when the image isn't white but it's completely black. In which case introduction of black pixels totally screws me over. For the past few weeks I just couldn't find a good workaround using Matlab.
>
> I do however have a Java code that does exactly what I am looking for.
>
> AffineTransform affineTransform = new AffineTransform();
> //rotate the image
> affineTransform.rotate(Math.toRadians(45));
> //draw the image using the AffineTransform
> g2d.drawImage(m_image, m_affineTransform, this);
>
> So here is what I have done so far:
>
> I = imread("image.tif');
> javaImage = im2java(I);
> import java.awt.*;
> and anything I try from here doesn't work...
>
> But I have no clue how to implement the affineTransforms within Matlab context (using Java). If someone would be kind enough to show me how to do any of the AffineTransforms from Matlab I'd greatly appreciate it.
>
> [Disclaimer: I searched Google, read and implemented all Mathworks Java Tutorials].
>
> thanks in advance,
> Aleks
Hi Aleks,
I don't know about the Java idea but I have run into that issue of it always using black as the fill value. The answer in MATLAB is to go to the lower level functions where you have control over the fill
So this should work:
ang = 45;
phi = ang*pi/180; %deg to rad
rotate = maketform('affine',[ cos(phi) sin(phi) 0; ...
-sin(phi) cos(phi) 0; ...
0 0 1 ]);
%make an all black image
I(1:100,1:100,1:3) = 0;
J = imtransform(I,rotate,'FillValues',[255;255;0]);
imshow(I), figure, imshow(J)
|