%%Matrix dimensions must agree.
%Error in crop4 (line 86) ZTerm=Z.*ROI';
J=imread('3.bmp');imshow(J)set(gcf,'position',[1 1 600 600]);% %binary img
% J=I(:,:,1)>160;
% imshow(J)
% set(gcf,'position',[1 1 600 600]);
%%Thining
% Ridge thining is to eliminate the redundant pixels of ridges till the
% ridges are just one pixel wide.
K=bwmorph(~J,'thin','inf');imshow(~K)set(gcf,'position',[1 1 600 600]);%%Minutiae
% We filter the thinned ridge map by the filter "minutie". "minutie"
% compute the number of one-value of each 3x3 window:
% * if the central is 1 and has only 1 one-value neighbor, then the central
% pixel is a termination.
% * if the central is 1 and has 3 one-value neighbor, then the central
% pixel is a bifurcation.
% * if the central is 1 and has 2 one-value neighbor, then the central
% pixel is a usual pixel.
fun=@minutie;L = nlfilter(K,[3 3],fun);%%Termination
LTerm=(L==1);imshow(LTerm)LTermLab=bwlabel(LTerm);propTerm=regionprops(LTermLab,'Centroid');CentroidTerm=round(cat(1,propTerm(:).Centroid));imshow(~K)set(gcf,'position',[1 1 600 600]);hold onplot(CentroidTerm(:,1),CentroidTerm(:,2),'ro')%%Bifurcation
LBif=(L==3);LBifLab=bwlabel(LBif);propBif=regionprops(LBifLab,'Centroid','Image');CentroidBif=round(cat(1,propBif(:).Centroid));plot(CentroidBif(:,1),CentroidBif(:,2),'go')D=6;%Process 1
Distance=DistEuclidian(CentroidBif,CentroidTerm);SpuriousMinutae=Distance<D;[i,j]=find(SpuriousMinutae);CentroidBif(i,:)=[];CentroidTerm(j,:)=[];%Process 2
Distance=DistEuclidian(CentroidBif);SpuriousMinutae=Distance<D;[i,j]=find(SpuriousMinutae);CentroidBif(i,:)=[];%Process 3
Distance=DistEuclidian(CentroidTerm);SpuriousMinutae=Distance<D;[i,j]=find(SpuriousMinutae);CentroidTerm(i,:)=[];hold offimshow(~K)hold onplot(CentroidTerm(:,1),CentroidTerm(:,2),'ro')plot(CentroidBif(:,1),CentroidBif(:,2),'go')hold off%Suppress extrema minutiae
%Once we defined the ROI, we can suppress minutiae external to this ROI.
[m,n]=size(I(:,:,1));indTerm=sub2ind([m,n],CentroidTerm(:,1),CentroidTerm(:,2));Z=zeros(m,n);Z(indTerm)=1;ZTerm=Z.*ROI';[CentroidTermX,CentroidTermY]=find(ZTerm);indBif=sub2ind([m,n],CentroidBif(:,1),CentroidBif(:,2));Z=zeros(m,n);Z(indBif)=1;ZBif=Z.*ROI';[CentroidBifX,CentroidBifY]=find(ZBif);imshow(I)hold onplot(CentroidTermX,CentroidTermY,'ro','linewidth',2)plot(CentroidBifX,CentroidBifY,'go','linewidth',2)Kopen=imclose(K,strel('square',7));KopenClean= imfill(Kopen,'holes');KopenClean=bwareaopen(KopenClean,5);imshow(KopenClean)KopenClean([1 end],:)=0;KopenClean(:,[1 end])=0;ROI=imerode(KopenClean,strel('disk',10));imshow(ROI)imshow(I)hold onimshow(ROI)alpha(0.5)hold onplot(CentroidTerm(:,1),CentroidTerm(:,2),'ro')plot(CentroidBif(:,1),CentroidBif(:,2),'go')hold off%orientation
Table=[3*pi/4 2*pi/3 pi/2 pi/3 pi/4 5*pi/6 0 0 0 pi/6 pi 0 0 0 0 -5*pi/6 0 0 0 -pi/6 -3*pi/4 -2*pi/3 -pi/2 -pi/3 -pi/4];for ind=1:length(CentroidTermX) Klocal=K(CentroidTermY(ind)-2:CentroidTermY(ind)+2,CentroidTermX(ind)-2:CentroidTermX(ind)+2); Klocal(2:end-1,2:end-1)=0; [i,j]=find(Klocal); OrientationTerm(ind,1)=Table(i,j);enddxTerm=sin(OrientationTerm)*5;dyTerm=cos(OrientationTerm)*5;figureimshow(K)set(gcf,'position',[1 1 600 600]);hold onplot(CentroidTermX,CentroidTermY,'ro','linewidth',2)plot([CentroidTermX CentroidTermX+dyTerm]',... [CentroidTermY CentroidTermY-dxTerm]','r','linewidth',2)%%Bifurcation Orientation
% For each bifurcation, we have three lines. So we operate the same process than in termination case three times.
for ind=1:length(CentroidBifX) Klocal=K(CentroidBifY(ind)-2:CentroidBifY(ind)+2,CentroidBifX(ind)-2:CentroidBifX(ind)+2); Klocal(2:end-1,2:end-1)=0; [i,j]=find(Klocal); if length(i)~=3 CentroidBifY(ind)=NaN; CentroidBifX(ind)=NaN; OrientationBif(ind)=NaN; else for k=1:3 OrientationBif(ind,k)=Table(i(k),j(k)); dxBif(ind,k)=sin(OrientationBif(ind,k))*5; dyBif(ind,k)=cos(OrientationBif(ind,k))*5; end end endplot(CentroidBifX,CentroidBifY,'go','linewidth',2)OrientationLinesX=[CentroidBifX CentroidBifX+dyBif(:,1);CentroidBifX CentroidBifX+dyBif(:,2);CentroidBifX CentroidBifX+dyBif(:,3)]';OrientationLinesY=[CentroidBifY CentroidBifY-dxBif(:,1);CentroidBifY CentroidBifY-dxBif(:,2);CentroidBifY CentroidBifY-dxBif(:,3)]';plot(OrientationLinesX,OrientationLinesY,'g','linewidth',2)%Validation
MinutiaTerm=[CentroidTermX,CentroidTermY,OrientationTerm];MinutiaBif=[CentroidBifX,CentroidBifY,OrientationBif];saveMinutia('John Doe',MinutiaTerm,MinutiaBif);
MATLAB: Hello, I have the following code and couldn’t figure out what I am doing wrong. I am getting the following error,
matrix dimension
Best Answer