Straighten edges of black rectangle in binary image
이전 댓글 표시
I have a binary image that represents a 'rectangle'. The rectangle is not perfect because a top view of the box was taken (then converted to a binary image). My objective is to find four corner points of the black rectangle. In order for the corner function to work the edges must be completely straight.

clc; clear;
image = imread('0148pm.jpg');
g = rgb2gray(image)
level = graythresh(g);
binary = im2bw(image,level);
imwrite(binary,'imageBinary.jpg');
% Iinv = ~binary; %Invert your binary image
% Iinv = bwareaopen(Iinv,20); %Get rid of small areas (below your size criterion)
% I = ~Inv; %Invert back
imshow(I);
% fill = bwmorph(binary,'hbreak');
%
% f = bwmorph(fill,'majority');
%
% k = bwmorph(f,'close');
%corner algorithm///////////////////////////////////////////////////
% C = corner(k,'MinimumEigenvalue', 4)
% imtool(k);
% hold on
% plot(C(:,1), C(:,2), 'r*');
%end corner algorithm///////////////////////////////////////////////
댓글 수: 3
Image Analyst
2013년 4월 24일
What do you really want to do: find corners or straighten edges? Do you know it's possible to straighten the square without even finding the corners?
Kal
2013년 4월 24일
Kal
2013년 4월 24일
편집: Image Analyst
2013년 4월 24일
채택된 답변
추가 답변 (2개)
Image Analyst
2013년 4월 24일
0 개 추천
Why not use hough() and look for line intersections? There is an example for it in the help.
Jeff E
2013년 4월 24일
The following may be helpful in validating any solution you do end up finding. If the rectangles in your images are rotated to any significant degree, just change "diamond" into "disk" to get a more robust, but slightly more noisy result.
bw = im2bw(imread('w0lwro.jpg'));
bw = ~bwareaopen(~bw, 5000);
cmask = imclose(bw, strel('diamond', 20));
cornermask = cmask & ~bw;
cornermask = bwareaopen(cornermask, 50);
The result is a binary mask that should contain, or be very close to, your corners, either through corner point detection or hough transform as suggested by Image Analyst.
카테고리
도움말 센터 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





