Can I have rotate image with white background
By default if we use imrotate it rotate image with black background can I have rotated image with white background?

 Risposta accettata

Sean de Wolski
Sean de Wolski il 23 Giu 2011

5 voti

Irot = imrotate(I,theta);
Mrot = ~imrotate(true(size(I)),theta);
Irot(Mrot&~imclearborder(Mrot)) = 255;
%View 'er
imtool(Irot)
Edited to be more robust/simpler

4 Commenti

Dipak
Dipak il 24 Giu 2011
Hi sean First of all Thankyou very much for giving me the ans.
priya7 D Mello
priya7 D Mello il 23 Feb 2012
Thank you very much. I needed this code badly for my project :)
Leo Wong
Leo Wong il 5 Set 2018
You are a genius Sean. Your code was the missing piece to complete my project :)
Ali RAHIMI KHOJASTEH
Ali RAHIMI KHOJASTEH il 1 Apr 2021
Thank you, it works for me

Accedi per commentare.

Più risposte (2)

Walter Roberson
Walter Roberson il 23 Giu 2011

1 voto

imrotate() always fills with 0.
If your image is floating point, then one way to proceed would be to put a border of NaN around your image, and rotate that. The resulting image should have NaN in it; set the NaN and everything outside to the background color you want.

1 Commento

Dipak
Dipak il 24 Giu 2011
Thanks Walter For the reply.
Thank you.

Accedi per commentare.

Richiesto:

il 23 Giu 2011

Risposto:

DGM
il 30 Dic 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by