Straighten edges of black rectangle in binary image
Mostrar comentarios más antiguos
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 comentarios
Image Analyst
el 24 de Abr. de 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
el 24 de Abr. de 2013
Kal
el 24 de Abr. de 2013
Editada: Image Analyst
el 24 de Abr. de 2013
Respuesta aceptada
Más respuestas (2)
Image Analyst
el 24 de Abr. de 2013
0 votos
Why not use hough() and look for line intersections? There is an example for it in the help.
1 comentario
Kal
el 25 de Abr. de 2013
Jeff E
el 24 de Abr. de 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.
Categorías
Más información sobre Image Processing Toolbox en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





