Code generation requires variable 'ac' to be fully defined before subscripting it. Code generation requires variable 'an' to be fully defined before subscripting it. Code generation requires variable 'A11' to be fully defined before subscripting it.
46 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
function [A] = segmentIm(I,seedp,th,L)
%UNTITLED6 Summary of this function goes here
% Detailed explanation goes here
%.............................................Probability Map Computation
I1=rgb2hsv(I); %Converting image rgb to hsv
H=I1(:,:,1);
S=I1(:,:,2);
V=I1(:,:,3);
A=zeros(size(L));
a=8;
%............................color channel modification
Sm=log((a*S)+1)/log(a+1);
Vm=log((a*V)+1)/log(a+1);
Hm=H-1/12;
idx=find(Hm<0);
Hm(idx)=1+Hm(idx);
%Sm=S;
%I1m=cat(3, Hm,Sm,Vm);
%.....................................................
Vk=0;
Vw=1;
Sw=0;
Hr=11/12;
Sr=1;
Vr=1;
Hy=1/12;
Sy=1;
Vy=1;
%............................Distance Calculation
Dr=sqrt((Hm-Hr).^2+(Sm-Sr).^2+(Vm-Vr).^2);
Dy=sqrt((Hm-Hy).^2+(Sm-Sy).^2+(Vm-Vy).^2);
Dk=Vm-Vk;
Dw=sqrt((Vm-Vw).^2+(Sm-Sw).^2);
%...............................................
Pr=1./(1+(Dr./Dy).^2+(Dr./Dk).^2+(Dr./Dw).^2);
Py=1./((Dy./Dr).^2+1+(Dy./Dk).^2+(Dy./Dw).^2);
Pk=1./((Dk./Dr).^2+(Dk./Dy).^2+1+(Dk./Dw).^2);
Pw=1./((Dw./Dr).^2+(Dw./Dy).^2+(Dw./Dk).^2+1);
%..................................................
% %
% figure, imshow(Pr,[])
% figure, imshow(Py,[])
% figure, imshow(Pk,[])
% figure, imshow(Pw,[])
% BW = boundarymask(L);
% figure,imshow(imoverlay(I,BW,'cyan'),'InitialMagnification',67)
% s = regionprops(L, 'Centroid');
% %imshow(imoverlay(I,BW,'cyan'),'InitialMagnification',67)
%
% for k1 = 1:numel(s)
% c = s(k1).Centroid;
% text(c(1), c(2), sprintf('%d', k1), ...
% 'HorizontalAlignment', 'center', ...
% 'VerticalAlignment', 'middle','Color','b');
% end
% hold off
%.............................................Superpixel Region Growing
In_sp=find(L==seedp);
nps=numel(In_sp);
A(In_sp)=1;
bSup=(L==seedp);
spr=Pr.*bSup;
spy=Py.*bSup;
spk=Pk.*bSup;
spw=Pw.*bSup;
ac(1,:)=sum(spr(:))/nps;
ac(2,:)=sum(spy(:))/nps;
ac(3,:)=sum(spk(:))/nps;
ac(4,:)=sum(spw(:))/nps;
av=ac;
wSup=zeros(100,1);
nwSup=zeros(100,1);
aap=1;
oc=0;
tc=0;
while (length(aap))~=0
adjacent_pixels = imdilate(A, ones(3,3)) & ~A;
App=adjacent_pixels.*L;
% negL=unique(App);
% negL1=nonzeros(negL);
negL=nonzeros(App);
negL1=unique(negL,'stable');
negL1n= sortbypos(A,App,negL1);
% negL1n=negL1;
for ii=1:length(negL1n)
ch_sup=negL1n(ii);
a1=ismember(ch_sup,nwSup);
a2=ismember(ch_sup,wSup);
if a1==0 && a2==0
Ab=zeros(size(I(:,:,1)));
%an=zeros(4,1);
idx1=find(L==ch_sup);
Ab(idx1)=1;
bSupc=Ab;
cspr=Pr.*bSupc;
cspy=Py.*bSupc;
cspk=Pk.*bSupc;
cspw=Pw.*bSupc;
an(1,:)=sum(cspr(:))/numel(idx1);
an(2,:)=sum(cspy(:))/numel(idx1);
an(3,:)=sum(cspk(:))/numel(idx1);
an(4,:)=sum(cspw(:))/numel(idx1);
D=sqrt(sum((av - an) .^ 2));
if D<=th
A(idx1)=1;
oc=oc+1;
wSup(oc,:)=ch_sup;
av(1,:)=(av(1,:)+an(1,:))/2;
av(2,:)=(av(2,:)+an(2,:))/2;
av(3,:)=(av(3,:)+an(3,:))/2;
av(4,:)=(av(4,:)+an(4,:))/2;
else
tc=tc+1;
nwSup(tc,:)=ch_sup;
A(idx1)=0;
A11(idx1)=1;
end
end
end
%............................................................
nwSup1=nonzeros(nwSup);
Lia1 = ismember(negL1,nwSup1);
aap=find(Lia1<1);
end
end
0 Kommentare
Antworten (2)
Walter Roberson
am 23 Jan. 2021
Near the top of the code, you need to add
ac = zeros(4,1);
an = zeros(4,1);
A1 = zeros(size(L));
2 Kommentare
Walter Roberson
am 23 Jan. 2021
The first two errors tell me that your input signal I is a 2D array rather than a 3D array (RGB)
A number of the following errors are consequences of that error in size of the input signal.
Darshan Ramakant Bhat
am 23 Jan. 2021
Like Walter suggested you need to fully difine variables size before accessing it.
You can use %#codegen pragma at the beginning of your function to get all such issues highlighted.
I could modify the function a bit and and get it working with codegen. Please do a diff with the modified code and your code to check what exactly is changed. You can tweek it a little bit to suite your application.
Please use the attached files.
Hope this will be helpful
1 Kommentar
Darshan Ramakant Bhat
am 23 Jan. 2021
Also below chart will be helpful if you are getting strated with MATLAB Coder
Siehe auch
Kategorien
Mehr zu MATLAB Coder finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!