⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 crop.m

📁 A set of functions to calculate Hu s seven invariant moments. Good accuracy. Written for my Project
💻 M
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -