MATLAB: Imrotate help – black pixel border remains despite changing the colour of the background

imageimage processingImage Processing Toolboximrotate

Hello,
With the imrotate function, the negative space of the image is automatically replaced with black. My attached script works great and changes this to the colour I need — grey. However, if the rotation is not along a right angle, a tiny border of black pixels remains (see attached image). Please tell me there is a way to remove them?
Thanks in advance for your help.
RGB = imread('wheel_final.jpg');
rotationdegree = randi(360);
RGB_Rotated = imrotate(RGB,rotationdegree,'bilinear','crop');
Mrot = ~imrotate(true(size(RGB)), rotationdegree,'bilinear','crop');
RGB_Rotated(Mrot&~imclearborder(Mrot))=150;
imtool(RGB_Rotated);

Best Answer

Try the nearest option instead of the bilinear option.