Question

I'm trying to detect the screen border from the image (In need the 4 corners). This is the Image:

enter image description here

I used HOUGH transform to detect lines and intersection points (the black circles) and this is the result:

enter image description here

Now I need to find the 4 corners or the 4 lines.. everything that will help me to crop the image, What can I do? Maybe use the screen aspect ratio? but how? I'm using Matlab.

Thanks.

Was it helpful?

Solution

A naive first approach that would do the trick if and only if you have same image conditions (background and laptop).

  1. Convert your image to HSV (examine that in HSV the image inside the screen is the only portion of the image with high Saturation, Value values)
  2. Create a mask by hard thresholding the Saturation and Value channels
  3. Dilate the mask to connect disconnected regions
  4. Compute the convex hull to get the mask boundaries

See a quick result: enter image description here Here is the same mask with the original image portion that makes it through the mask: enter image description here

Here is the code to do so:

img = imread( 'imagename.jpg'); % change the image name
hsv = rgb2hsv( img);
mask = hsv(:,:,2)>0.25 & hsv(:,:,3)>0.5;
strel_size = round(0.025*max(size(mask)));
dilated_mask=imdilate(mask,strel('square',strel_size));
s=regionprops(dilated_mask,'BoundingBox','ConvexHull');
% here Bounding box produces a box with the minimum-maximum white pixel positions but the image is not actually rectangular due to perspective...
imshow(uint8(img.*repmat(dilated_mask,[1 1 3])));
line(s.ConvexHull(:,1),s.ConvexHull(:,2),'Color','red','LineWidth',3);


You may, of course, apply some more sophisticated processing to be a lot more accurate and to correct the convex hull to be just a rectangular shape with perspective, but this is just a 5 minutes attempt just to showcase the approach...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top