필터 지우기
필터 지우기

How to detect and crop boundry of the given image deleting unwanted space?

조회 수: 1 (최근 30일)
I want to crop the "Capture.JPG" image from "1.jpg"(left image=>right image)
I used the imcrop but it doesn't gave me the desired image.
My code is given below. Code requires two folders "Testing Images" and "Preprocess Testing Images".
code :-
Imges = dir('Testing Images\*jpg');
InputSet=[];
OutputSet=[];
for i = 1:numel(Imges)
filename = strcat('Testing Images\',Imges(i).name);
I=imread(filename);
Igray = rgb2gray(I);
imwrite(Igray,strcat('Preprocessed Testing Images\GrayScale',int2str(i),'.jpg'));
Ibw = im2bw(Igray,graythresh(Igray));
imwrite(Ibw,strcat('Preprocessed Testing Images\Binary',int2str(i),'.jpg'));
Ibwn=wiener2(Ibw,[5 5]);
imwrite(Ibwn,strcat('Preprocessed Testing Images\AfterNoise',int2str(i),'.jpg'));
Iedge = edge(Ibwn,'canny');
imwrite(Iedge,strcat('Preprocessed Testing Images\AfterEdge()',int2str(i),'.jpg'));
se = strel('arbitrary',2);
Iedge2 = imdilate(Iedge, se);
imwrite(Iedge2,strcat('Preprocessed Testing Images\AfterImdilate()',int2str(i),'.jpg'));
Ifill= imfill(Iedge2,'holes');
imwrite(Ifill,strcat('Preprocessed Testing Images\AfterImfill()',int2str(i),'.jpg'));
IfillInvert=imcomplement(Ifill);
imwrite(IfillInvert,strcat('Preprocessed Testing Images\AfterImInvert()',int2str(i),'.jpg'));
Ifinal1 = bwareaopen(IfillInvert,100);
[Ilabel num] = bwlabel(Ifinal1);
Iprops = regionprops(Ilabel);
Ibox = [Iprops.BoundingBox];
Icrop = imcrop(I,Ibox);
imwrite(Icrop,strcat('Preprocessed Testing Images\AfterCrop1()',int2str(i),'.jpg'));
end
  댓글 수: 7
Indunie Florence
Indunie Florence 2014년 6월 1일
no, It doesn't crop above image correctly. Actually above code is a testing code for cropping. Your code is working to the given image by me. It is a very clear card. According to my target I use images with some noises. After some functions worked, it produces a image without boundary. I want to crop it too. Your code didn't work in this situation.
Can you help me.Image is given below. It is in binary mode.
Image Analyst
Image Analyst 2014년 6월 1일
It's a different card so will require a different algorithm. Since it's not a green box, you need to invert the image, then call bwconvhull(), then bwlabeland regionprops, finally imcrop. Give it a try.

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2014년 5월 31일
Try the attached test.m file to produce this image.
  댓글 수: 1
Ali Haider
Ali Haider 2016년 2월 22일
Hi,
I want to crop text in bounding box from an image. plz help me out in this.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Segmentation and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by