# how can i automatically crop this image? if it is possible.

조회 수: 5 (최근 30일)
SvenvdB . 2021년 6월 29일
댓글: Walter Roberson . 2021년 6월 29일
I have a script that automatically calculates de surface area of a shape. The problem is i have to manually crop a the images.
Does anyone know if this i possible to do. and tips on how to do it.
This is an example of the picture i want to crop. i want to crop it like this: this i my code for calculating surface area:
imshow(i);
%%Convert RGB to Gray
imshow(gry,[]);
%%Image segementation by thresholding
level=0.7;
thres=im2bw(gry,level);
imshow(thres);
%sort image
format long g
props = regionprops(~thres, 'Area');
sA = sort([props.Area])
mA = min(sA(1:end-1))
relA = sA(end)/mA
small_area = 10*10;
absA = relA * small_area
##### 댓글 수: 1표시 없음숨기기 없음
Walter Roberson 2021년 6월 29일
I knew that looked familiar ;-)

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

### 채택된 답변

Joseph Cheng 2021년 6월 29일
well, you can find the corner squares by doing the following:
figure(1),subplot(221),imshow(img);
%%Convert RGB to Gray
%find corner squares;
[rgion] = find(rsum~=0);
[cgion] = find(csum~=0);
subplot(224),imshow(img(rgion(1):rgion(end),cgion(1):cgion(end),:)) the area in the bwareafilt was selected from your calculation of the regionprops. similarly with the region props you can find the centroid of these corner markers and perform a rotation if you need to morph the image.
##### 댓글 수: 2표시 이전 댓글 수: 1숨기기 이전 댓글 수: 1
Joseph Cheng 2021년 6월 29일
it can be whatever you want it to be. if you follow the step by step code you can see that i find the extremes/bounds of the cropped image by the defined rgion and cgion (row and column regions):
Croppedimg = img(rgion(1):rgion(end),cgion(1):cgion(end),:);
so you can save the original image in a variable by specifying the indexes of the original image

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

### 카테고리

Help CenterFile Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기

R2021a

### Community Treasure Hunt

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

Start Hunting!