Azzera filtri
Azzera filtri

Error using sub2ind (line 43) Out of range subscript.!!

7 visualizzazioni (ultimi 30 giorni)
Hi evreyone
I found this program that works well until this line
""Error in test_munitie (line 96)
indTerm=sub2ind([m,n],CentroidTerm(:,1),CentroidTerm(:,2));"""
I did not understand where is the problem ? any help please
thanks
clear all,close all,clc
I=imread('Empreinte.bmp');
imshow(I)
set(gcf,'position',[1 1 600 600]);
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]);
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')
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);
imshow(KopenClean)
KopenClean([1 end],:)=0;
KopenClean(:,[1 end])=0;
ROI=imerode(KopenClean,strel('disk',10));
imshow(ROI)
%%
imshow(I)
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(I(:,:,1));
indTerm=sub2ind([m,n],CentroidTerm(:,1),CentroidTerm(:,2));%%%!!!!!!!ERROR
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)

Risposta accettata

Walter Roberson
Walter Roberson il 27 Mag 2019
Centroid information is returned with x and then y. x corresponds to column and y corresponds to rows. When you try to convert the x y to subscript you are passing in the order x y which is column row when you need to be passing in row column, which is y x
  3 Commenti
Walter Roberson
Walter Roberson il 27 Mag 2019
You take the centroid and extract a 5 x 5 block centered there, and zero out the middle of the block leaving only the edges. Then you assume that exactly one pixel is non-zero on those edges. There might be no non-zero pixels, or there might be several.
Richard Hall
Richard Hall il 27 Feb 2020
Is there a design reson why regionprops uses [x y] and sub2ind uses [y x]?
Or is this a "gotcha" in the way MatLab was written?
(I just happen to be using the same source code and just figured out this problem.)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Images in Help Center e File Exchange

Prodotti


Release

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by