From: Lynn MacDonald on 22 Jul 2010 14:46 Hi, I wrote this code to rotate a small image through 360 degrees, pad it with zeros so that it is square with odd dimension and write it to file. The original version which was on a grayscale image works fine. But when I attempt to change it for rgb, it runs well until it hits 45 degrees. At that point, if it is padding the rows it works fine, but if it is padding the columns, it quits. This is because it reads the column width of ygr incorrectly. I have attempted to read the value two different ways, and neither works. The nearest reply I found to this is http://www.mathworks.com/matlabcentral/newsreader/view_thread/264225 but I attempted what was mentioned there to no avail. Also, I am using 2010a. If you notice anything not related to the problem that I could do to improve my code, please point it out as I'm just learning and can apply this to other areas. Thanks, Lynn Here is the code: %This script takes an image and rotates through 360 degrees, saving %pictures every deg degrees. The final image is padded with black so that %it is square with oddxodd dimension. %Open image. Set the degrees between each picture. yg = imread('.\put some rgb image file in here); deg = 2; numpix = 360/deg; %For each angle, create a filename, rotate the picture, fix the dimension, %pad with zeros in the deficient dimension, and then write to file. for i = 1:numpix ygr = yg; ang = i*deg; numb = num2str(i); filen = strcat('.\folder name\image', num*deg,'.tif'); ygr = imrotate(ygr,ang,'bilinear'); [r c] = size(ygr); %sizeygr = size(ygr); %r = sizeygr(1); %c = sizeygr(2); if rem(r, 2) == 0 r = r + 1; ygr(r, c) = 0; end if rem(c, 2) == 0 c = c + 1; ygr(r, c) = 0; end buffer = (r-c)/2; if buffer > 0 bufferbox = zeros(r, buffer, 3); ygr = horzcat(bufferbox, ygr, bufferbox); elseif buffer < 0 bufferbox = zeros(-buffer, c, 3); ygr = vertcat(bufferbox, ygr, bufferbox); end imwrite(ygr, filen, 'tif') clear ygr; end
From: Lynn MacDonald on 22 Jul 2010 14:56 Sorry, I am aware that the line [r c] = size(ygr); should read [r c ~] = size(ygr); I don't know how to edit my post, so I'm posting this here.
From: Lynn MacDonald on 22 Jul 2010 15:10 "Lynn MacDonald" <willowsword(a)gmail.com> wrote in message <i2a485$qmj$1(a)fred.mathworks.com>... > Sorry, I am aware that the line > [r c] = size(ygr); > > should read > [r c ~] = size(ygr); > > I don't know how to edit my post, so I'm posting this here. And...one more thing (I'm very sorry)...my naming is messed up, if you do this: angname = num2str(ang); filen = strcat('.\somefilename', angname,'.tif'); where the filename is, it will work better. I was trying to make it generic, but deleted out half my strcat string and typed it back in incorrectly.
|
Pages: 1 Prev: Report Generator Style Sheet help Next: Animation in a Matlab plot |