Straighten edges of black rectangle in binary image
Mostra commenti meno recenti
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 Commenti
Image Analyst
il 24 Apr 2013
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
il 24 Apr 2013
Kal
il 24 Apr 2013
Modificato: Image Analyst
il 24 Apr 2013
Risposta accettata
Più risposte (2)
Image Analyst
il 24 Apr 2013
0 voti
Why not use hough() and look for line intersections? There is an example for it in the help.
1 Commento
Kal
il 25 Apr 2013
Jeff E
il 24 Apr 2013
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.
Categorie
Scopri di più su Image Processing Toolbox in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





