# Need to detect the edges of a rectangle using Image processing?

20 Ansichten (letzte 30 Tage)
Jeen Xavier am 30 Okt. 2020
Kommentiert: Jeen Xavier am 30 Okt. 2020
So I first need to read the image file of student ID card get the edges of the ID card and draw a rectangle covering the edges and the crop the detected edges of the image.
These are the methods I used so far
--> To convert to grayscale - rgb2gray()
--> To detect the edges - edge() using the Canny method
--> To get only edge data - bwconvhull()
--> To draw the rectangle over the ID - regionprops
These are my main idea the solutions works but its not that accurate. Pls if somebody knows it that would be really helpful
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Antworten (1)

drummer am 30 Okt. 2020
Bearbeitet: drummer am 30 Okt. 2020
What if you use dilation-erosion approaches?
##### 1 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
Jeen Xavier am 30 Okt. 2020
This is my existing code which I have made its not the best, Do you know any suitable fix for my code to be more optimal?
% Convert the image to a gray scale image
rgb = rgb2gray(f);
BW1 = edge(rgb,'Canny'); %putting the edge function to mask the image
CH = bwconvhull(BW1);
[L n] = bwlabel(CH,8);
blobs = regionprops(L, 'BoundingBox');
% blobs(1).BoundingBox % the third and fourth row shows the width and height
width = blobs(1).BoundingBox(3)
height = blobs(1).BoundingBox(4)
imshow(f);
rectangle('Position',blobs(1).BoundingBox,'Edgecolor','g');
% cropping the new image with respect to the rectangle created
new_crop = imcrop(f, [blobs(1).BoundingBox(1) blobs(1).BoundingBox(2) blobs(1).BoundingBox(3) blobs(1).BoundingBox(4)]);
imshow(new_crop)

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Image Arithmetic finden Sie in Help Center und File Exchange

R2017a

### Community Treasure Hunt

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

Start Hunting!

Translated by