crop.m

来自「A set of functions to calculate Hu s sev」· M 代码 · 共 32 行

M
32
字号
function imout = crop(inim)
%function to crop a binary image
%written for Malayalam OCR on 21/10/2008

%--usage
%  outputimage=crop(inputimage);
%--inputs
%  in = image binary data
%  
%--output
%  imout= the cropped image

if ~islogical(inim)			%check if the image is binary ?
	level=graythresh(inim);	%if not find the threshold level
	inim=im2bw(inim,level);	%convert it to binary with the threshold level obtained 
end

i=~inim;					%invert the image , 

[x y]=find(i);				%find indices of nonzero elemnts

xmin=min(x);				%find lowest row index of nonzero element
xmax=max(x);				%find highest row index of nonzero element

ymin=min(y);				%find lowest column index of nonzero element
ymax=max(y);				%find highest column index of nonzero element

imout=i(xmin:xmax,ymin:ymax);	%crop out the white parts
imout=~imout;				%invert the image


	

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?