-1
두 벡터, 즉 x 좌표를 저장하는 벡터와 y 좌표를 저장하는 벡터가 있습니다. 루프에서 액세스하려고하면 루프의 모든 반복에서 동일한 좌표가 반환됩니다.Matlab, 벡터 요소에 접근하기
내 루프 수정을 도와 줄 수있는 사람이 있습니까? 당신의 중첩 for
루프 두 가지 문제가 있습니다
N2=8;
info2 = repmat(struct, ceil(size(Z, 1)/N2), ceil(size(Z, 2)/N2)); %creates another array of structs consisting of an m-by-n tiling
for row1 = 1:N2:size(Z, 1)%loop through each pixel in the 8x8 window
for col1 = 1:N2:size(Z, 2)
x = (row1 - 1)/N2 + 1;
y = (col1 - 1)/N2 + 1;
imgWindow2 = Z(row1:min(end,row1+N2-1), col1:min(end,col1+N2-1));
average2 = mean(imgWindow2(:));
window2(x,y).average=average2;
% if the intensity of the 8x8 window is greater than
% 210 then considered suspicious- calculate GLCM-
if average2>100
% display('greater than 100');
%best direction is 0
offsets0 = [0 1];
glcms = graycomatrix(imgWindow2,'Offset',offsets0);
stats = graycoprops(glcms,'all'); %normalize GLCM so that values are between 0 and 1
correlation=[stats.Correlation];
contrast=[stats.Contrast];
homogeneity=[stats.Homogeneity];
energy=[stats.Energy];
%if these conditions are met then this window
%contains an ROI
if (homogeneity > 0.9)
if (contrast<0.2)
if (energy>0.6)
for i=1:length(coordsX)
coordsX(i)=row1;
for j=1:length(coordsY)
coordsY(j)=col1;
end
end
for ii=1:length(coordsX)
coX=coordsX(ii);
for jj=1: length(coordsY)
coY=coordsY(jj)
Z1 = insertShape(Z, 'rectangle', [coX coY 8 8]);
figure(2);
end
end
end
end
end
고마워,이 수정 프로그램을 시도했지만 하나의 사각형 만 이미지에 나타납니다. 이미지는 매번 같은 위치에 사각형으로 여러 번 열립니다. 각 좌표에 대해 하나의 이미지에 여러 개의 직사각형이있는 이미지를 어떻게 표시 할 수 있는지 알고 있습니까? – user1853871
아마도 'hold on'을 사용하여 이전 직사각형이 플롯에 남아 있는지 확인해야 할 것입니다. – am304
감사합니다. 그러나 배열의 모든 x와 y 좌표는 같은 값입니다. – user1853871