Sir, i want to store image feature(Bifurcation and termination) into excel file rowwise (code attached herewith) But last image is overwritten, please give the soluation

1 view (last 30 days)
% Minutiae points are local ridge characteristics that occur at either a % ridge bifurcation or a ridge % ending. clear all; clc;
path = 'E:\MATLAB\R2016b\bin\img\PCA\my_PhD_Programs\Bifurcation\FingerPrint\training\'; tf=dir([path '/*.bmp']); offset=1;
%% Load image
for k = 1:length(tf)
img = [path '/' tf(k).name];
grayImage=imread(img);
I = rgb2gray(grayImage); I=imresize(I,[210 210]); imshow(I)
set(gcf,'position',[1 1 600 600]);
%% Enhancement % %% Binarize % % We binarize the image. After the operation, ridges in the fingerprint are % % highlighted with black color while furrow are white. 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 on plot(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') %% Remarks % We have a lot of spurious minutae. % We are going to process them. % process 1: if the distance between a termination and a biffurcation is % smaller than D, we remove this minutiae % process 2: if the distance between two biffurcations is % smaller than D, we remove this minutia % process 3: if the distance between two terminations is % smaller than D, we remove this minutia 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 off imshow(~K) hold on plot(CentroidTerm(:,1),CentroidTerm(:,2),'ro') plot(CentroidBif(:,1),CentroidBif(:,2),'go') hold off
%% ROI % We have to determine a ROI. For that, we consider the binary image, and % we aply an closing on this image and an erosion. % With the GUI, I allow the use of ROI tools of MATLAB, to define manually % the ROI.
Kopen=imclose(K,strel('square',7));
KopenClean= imfill(Kopen,'holes'); KopenClean=bwareaopen(KopenClean,5);
KopenClean([1 end],:)=0; KopenClean(:,[1 end])=0; ROI=imerode(KopenClean,strel('disk',10));
%%
imshow(J) hold on imshow(ROI) alpha(0.5)
hold on plot(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(J(:,:,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 on plot(CentroidTermX,CentroidTermY,'ro','linewidth',2) plot(CentroidBifX,CentroidBifY,'go','linewidth',2)
%% Orientation % Once we determined the differents minutiae, we have to find the % orientation of each one 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]; %% Termination Orientation % We have to find the orientation of the termination. % For finding that, we analyze the position of the pixel on the boundary of % a 5 x 5 bounding box of the termination. We compare this position to the % Table variable. The Table variable gives the angle in radian. 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); end dxTerm=sin(OrientationTerm)*5; dyTerm=cos(OrientationTerm)*5; figure imshow(K) set(gcf,'position',[1 1 600 600]); hold on plot(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
end
plot(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
%% Save in a text file % In this step, we are going to save the minutia in a file MinutiaTerm=[CentroidTermX,CentroidTermY,OrientationTerm]; MinutiaBif=[CentroidBifX,CentroidBifY,OrientationBif]; % saveMinutia1('BMS',MinutiaTerm,MinutiaBif);
%s1 = size(MinutiaFin,1);
%s2 = size(MinutiaSep,1);
s1 = size(MinutiaTerm,1) s2 = size(MinutiaBif,1);
A = {s1,s2}; xlswrite('bms.xlsx',A);
%output(k,1) = s1; %output(k,2) = s2;
% offset = offset + 1; end

Answers (0)

Community Treasure Hunt

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

Start Hunting!