Finding the four corners of each quadrilateral shapes in an image I am working on some image processing application using Matlab. The image after segmentation will look (more or less) like the figure below.



Now I want to find the four corners of each shape to crop it (I can access each using shape using its pixels as they have the same label after segmentation). I though of using a corner detector like harris, but it gives me many additional corners (as the sides of the shapes are not really straight due to discretization. for example, a straight line in an image will look like the image below, and hence will introduce many corners.



In even worse cases, due to the imperfection of the image segmentation, the corners may actually be lost and look like a curved line as shown below, even though the image before segmentation had these clear 4 corners.



Another approach that I thought of is first to crop each shape, and then to use the line information (using a line detection algorithm) of the 4 sides and find the intersection of each adjacent sides. However, the line information, again due to imperfect segmentation, may not exist (as a single straight line per side, a side could be detected as multiple non-connected lines). Moreover, again due to imperfect segmentation, the 4 sides may have some artifacts which will hinder proper line detection.

Any suggestions?
I though of using a corner detector like harris, but it gives me many additional corners (as the sides of the shapes are not really straight due to discretization.


In that case you should keep only the strongest feature points.


  the corners may actually be lost and look like a curved line as shown
  below, even though the image before segmentation had these clear 4
  corners.


In that case, you can use scale space, first blur the images excessively, then use Harris, or directly use SIFT detector and keep only the features points of the scale, that match your desired points.