Rotate Image segment without background
Mostrar comentarios más antiguos
I want to rotate image like this

I have rotated Image but I have got image like this in matlab

How to fix this problem in matlab Actually I want only rotate leaf part only not whole image. Is it posibble
4 comentarios
Gopichandh Danala
el 16 de Sept. de 2016
Editada: Gopichandh Danala
el 16 de Sept. de 2016
A simple trick is to change all the pixels other than the segment to a white background in your case.
I cropped your main image as u didn't post original image

and sample code is here:
leaf = imread('leaf.jpg');
figure, imshow(leaf, []);
rotateImg = imrotate(leaf,45); % rotate by 45 or 315 degrees
figure,
subplot(1,2,1)
imshow(rotateImg, [min(min(rotateImg(:))) max(max(rotateImg(:)))]);
newrotateImg = rotateImg;
newrotateImg(newrotateImg == 0) = 255; % make all 0 pixels to 255..
subplot(1,2,2)
imshow(newrotateImg, [min(min(newrotateImg(:))) max(max(newrotateImg(:)))]);

Hope it helps,
Image Analyst
el 16 de Sept. de 2016
Editada: Image Analyst
el 16 de Sept. de 2016
Gopichandh, please post it as an answer below, not a comment, so you might get credit for it. And read this.
And use the 'bbox', 'crop' option of imrotate() to keep the final image the same size.
That method is okay if the background is perfectly uniform gray level and there are no pixels of that gray level inside the leaf. Otherwise it's not 100% robust, since it rotates the background as well as the leaf, and sets black pixels that may be inside the leaf to white.
And see my attached demo if you want to find the farthest points so you know the angle you need to rotate by.
Gopichandh Danala
el 16 de Sept. de 2016
Thanks image analyst i will do as u suggested from now..
Malan Jayanka
el 18 de Sept. de 2016
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Image Segmentation and Analysis en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




