imagematlabimage-processingrotationcorner-detection

How to get the four corners of a rotated image?


I have an image rotated with imrotate as follow:

Im_requete=imread('lena.jpg');
Im_requete_G=rgb2gray(Im_requete);
Im_requete_G_scale_rot = imresize(imrotate(Im_requete_G,-20), 1.2);

I'm trying to get the coordinates (x, y) of the four corners of the rotated image as illustrated in the image below (red circle represents the desired corner):

Desired result

This is my code:

stat = regionprops(Im_requete_G_scale_rot,'Extrema'); %extrema detection of the image.
point = stat.Extrema;
hold on
figure,imshow(Im_requete_G_scale_rot)
hold on
for i = 2:2:length(point)
    x = point(i,1);
    y = point(i,2);
    plot(x,y,'o');
    text(x,y,num2str(i),'color','r')
end

But the resulting coordinates are somewhere along the edges and not where I wanted them to be, as illustrated in the second image:

Current, wrong result

Can someone please tell me what's wrong with this code?


Solution

  • I don't have a good explanation for this, but I suppose regionprops gets confused by the grayscale tones in the image. If we turn the rotated Lena into a logical array, your algorithm works properly:

    Im_requete_G_scale_rot = logical(imresize(imrotate(Im_requete_G,-20), 1.2)); % 3rd line
    

    enter image description here