MATLAB Answers

How to detect smarhtphone's screen in an image

조회 수: 4(최근 30일)
Itzhak Mamistvalov
Itzhak Mamistvalov 2021년 4월 23일
댓글: Itzhak Mamistvalov 2021년 4월 27일
Hey everyone.
Im trying to write a code which detecting smartphone's screens in an image.
Actually, i would like to get a picture of my desk in which my phone is 2 meters from the camera. The output will be just the phone's screen.
Note that the phone's screen displaying colored image (the next part of my project).
My first idea was to use HOUGH transform, but there are other lines that makes it difficult.
However, I know that the luminance of the screen and the colors are standing out of the other parts in the image.
Thanks.
Example of the input and the desired ouput:

채택된 답변

Tarunbir Gambhir
Tarunbir Gambhir 2021년 4월 26일
You can use the regionprops function to get a bounding box for the region of interest in your image. The 'BoundingBox' property of the regionprops function will give you the position and size of the smallest box containing the region.
You can use the following code to get your result.
% loading the image with correct orientation (portrait)
im = rot90(imread('inp.jpeg'),-1);
imshow(im);
% binarizing the image (pixel value as 0 or 1)
ib = im2bw(im);
% negating the image so the screen is
% the value 1 and the background is 0
ib = ~ib;
imshow(ib)
hold on
% getting all the possible bounding boxes in the image
% along with their area in pixels
stats = regionprops(ib,'BoundingBox','Area');
% getting indices of the largest 3 white pixel areas
[v,i] = maxk([stats.Area],3);
% displaying their bounding boxes on the image
for ind=1:length(i)
rectangle('Position', stats(i(ind)).BoundingBox,...
'EdgeColor','r', 'LineWidth', 3)
end
% after deciding which bounding box to crop with,
% we can use that to crop the original image.
% In this case we will select the largest area of white pixels,
% which is the phone screen.
imCropped = imcrop(im, stats(i(1)).BoundingBox);
figure;
imshow(imCropped);
cropped image

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by