次の関数を matlab から python に移植しようとしています。
function J = do_localmax(octave, thresh,smin)
[N,M,S]=size(octave);
nb=1;
k=0.0002;
J = [];
for s=2:S-1
for j=20:M-20
for i=20:N-20
a=octave(i,j,s);
if a>thresh+k ...
&& a>octave(i-1,j-1,s-1)+k && a>octave(i-1,j,s-1)+k && a>octave(i-1,j+1,s-1)+k ...
&& a>octave(i,j-1,s-1)+k && a>octave(i,j+1,s-1)+k && a>octave(i+1,j-1,s-1)+k ...
&& a>octave(i+1,j,s-1)+k && a>octave(i+1,j+1,s-1)+k && a>octave(i-1,j-1,s)+k ...
&& a>octave(i-1,j,s)+k && a>octave(i-1,j+1,s)+k && a>octave(i,j-1,s)+k ...
&& a>octave(i,j+1,s)+k && a>octave(i+1,j-1,s)+k && a>octave(i+1,j,s)+k ...
&& a>octave(i+1,j+1,s)+k && a>octave(i-1,j-1,s+1)+k && a>octave(i-1,j,s+1)+k ...
&& a>octave(i-1,j+1,s+1)+k && a>octave(i,j-1,s+1)+k && a>octave(i,j+1,s+1)+k ...
&& a>octave(i+1,j-1,s+1)+k && a>octave(i+1,j,s+1)+k && a>octave(i+1,j+1,s+1)+k
%if (a-maximum>0.00004)
%if (a-maximum>0.001)
J(1,nb)=j-1;
J(2,nb)=i-1;
J(3,nb)=s+smin-1;
nb=nb+1;
end
end
end
end
これは私が得たものです:
def localmax(Tmpo, thresh,smin,nb):
diff0= numpy.array(diff0)
M= len(Tmpo[:,0,0])
N= len(Tmpo[0,:,0])
T= len(Tmpo[0,0,:])
k=0.0002;
#%for each point of this scale space
#% we look for extrama bigger than thresh
J=numpy.zeros((4,1000))
for s in range(0,T-1):
for j in range(20,N-20):
for i in range(20,M-20):
a=Tmpo[i,j,s]
if a>thresh+k \
and a>Tmpo[i-1,j-1,s-1]+k and a>Tmpo[i-1,j,s-1]+k and a>Tmpo[i-1,j+1,s-1]+k \
and a>Tmpo[i,j-1,s-1]+k and a>Tmpo[i,j+1,s-1]+k and a>Tmpo[i+1,j-1,s-1]+k \
and a>Tmpo[i+1,j,s-1]+k and a>Tmpo[i+1,j+1,s-1]+k and a>Tmpo[i-1,j-1,s]+k \
and a>Tmpo[i-1,j,s]+k and a>Tmpo[i-1,j+1,s]+k and a>Tmpo[i,j-1,s]+k \
and a>Tmpo[i,j+1,s]+k and a>Tmpo[i+1,j-1,s]+k and a>Tmpo[i+1,j,s]+k \
and a>Tmpo[i+1,j+1,s]+k and a>Tmpo[i-1,j-1,s+1]+k and a>Tmpo[i-1,j,s+1]+k \
and a>Tmpo[i-1,j+1,s+1]+k and a>Tmpo[i,j-1,s+1]+k and a>Tmpo[i,j+1,s+1]+k \
and a>Tmpo[i+1,j-1,s+1]+k and a>Tmpo[i+1,j,s+1]+k and a>Tmpo[i+1,j+1,s+1]+k:
print 'we are here'
J[0,nb]=(j-1)
J[1,nb]=(i-1)
J[2,nb]=(s+smin-1)
nb += 1
J=J[numpy.nonzero(J)]
return J
それを実装しようとすると、python シェルで print ステートメントが表示されるという事実を考えると、空の配列が返されます。何か助けはありますか?