📄 segproc.m
字号:
% function cellarea=preprocessing(image,mheig,mwid,cof)
% image=wwx([1000,2000,1000,2000]);
tic
mheig=80;mwid=80;
mapc=imread('22_125.jpg'); % 10_125,22_107,25_54,23_38,23_107,21_125,20_58
mapg=rgb2gray(mapc);
mapg=255-double(mapg);
% mbw=im2bw(uint8(mapg),0.38);
image=mapg;
if ~isa(image,'uint8')
image=uint8(image);
end
m=size(image,1);
n=size(image,2);
bwimage=im2bw(image,.38);
seh=strel('line',200,0);
sev=strel('line',200,90);
seh1=strel('line',20,0);
sev1=strel('line',20,90);
se=strel('square',11);
bwieh=imerode(bwimage,seh);
bwioh=imdilate(bwieh,seh);
horiflh=bwioh;
bwiev=imerode(bwimage,sev);
bwiov=imdilate(bwiev,sev);
vertflv=bwiov;
% flout=or(vertflv,horiflh);
bwieh=imerode(~bwimage,seh);
bwioh=imdilate(bwieh,seh);
horiblh=bwioh;
bwiev=imerode(~bwimage,sev);
bwiov=imdilate(bwiev,sev);
vertblv=bwiov;
% blout=or(vertblv,horiblh);
hh=or(horiflh,horiblh);
hhd=imerode(~hh,sev1);
hhe=imdilate(hhd,sev1);
hho=~hhe;
vv=or(vertflv,vertblv);
vvd=imerode(~vv,seh1);
vve=imdilate(vvd,seh1);
vvo=~vve;
pout=or(vvo,hho);
poute=imerode(pout,se);
poutd=imdilate(poute,se);
poutd=imerode(~poutd,se);
poute=imdilate(poutd,se);
% out=~poute;
oout=poute;
ll=bwlabel(oout);
nn=max(max(ll));
pstat=imfeature(ll,'boundingbox');
oarea=[];
for ii=1:size(pstat,1);
mmid=pstat(ii).BoundingBox;
if (mmid(3)>mwid & mmid(4)>mheig) |(mmid(3)>mheig & mmid(4)>mwid)
oarea=[oarea; round(mmid(1)),round(mmid(2)),mmid(3),mmid(4)];
end
end
bwout=zeros(m,n);
for ii=1:size(oarea,1);
bwout(oarea(ii,2):oarea(ii,2)+oarea(ii,4)-1,oarea(ii,1):oarea(ii,1)+oarea(ii,3)-1)=1;
end
% allbox=[pstat.BoundingBox];
toc
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -