Can someone help me understand this code? It's a crop function for image processing.

조회 수: 1 (최근 30일)
I'm doing a project on gesture recognition. A part of the code is this function imcrop, as given below. Can someone explain how this works? And also how I can integrate it into the main code?
% MATLAB FUCTION imcrop TO CROP THE CAPTURED IMAGE
function imgout=imgcrop(imgin) %function definition
imgin = imresize(cropimg,[240,240]); %resize the original image
columnsum=sum(cropimg); %find the sum of column entries
rowsum=sum(cropimg'); %find the sum of row entries
q1=1;
q2=240;
q3=1;
q4=240;
for w=1:240 %search for the vertical cropping boundary
if (columnsum(1,w)>=10)
q1=w;
break;
end
end
for w=q1:240 %search for the vertical cropping boundary
if (columnsum(1,w)>=10)
q2=w;
end
end
for w=1:240 %search for the horizontal cropping boundary
if (rowsum(1,w)>=10) q3=w;
break;
end
end
for w=q3:240 %search for the horizontal cropping boundary
if (rowsum(1,w)>=50)
q4=w;
end
end
%crop the image between boundaries and resize to original
imgout=cropimg(q3:q4,q1:q2);
imgout=[zeros(q4-q3+1,160-(q2-q1+1)),imgout;zeros(120-(q4-q3+1),160)];
imgout=imresize(imgout,[120,160]);
imgout=double(imgout); %convert the image type to double for future use

채택된 답변

Image Analyst
Image Analyst 2014년 2월 3일
It doesn't work. As soon as it hits the first line
imgin = imresize(cropimg,[240,240]);
it will throw an exception because cropimg is undefined. It looks like something written by a very novice MATLAB programmer to find the rows and columns where the image is bright enough to be retained. Instead of all those for loops, they could simply use find(). Then they pad the image with zeros on the left and right and resize it for some reason. Basically they're masking out dark stuff outside the bounding box but doing it in a very odd way. If you want a masking app, just ask me for a demo.
  댓글 수: 3

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by