For loop help, Matrix manipulation

조회 수: 1 (최근 30일)
Derek
Derek 2011년 5월 11일
Hello,
Here is the updated code from a quesion I asked yesterday. I was given a TIFF image, which I imported into Matlab. I then had to find every pixel value greater than 149. My next step was to locate groups of nine points that each had values >149 that were arranged in a 3x3 sub matrix, which I called "kernals". The next step, which I am stuck on, requires me to find the mean of each "kernal", and sort the means into four groups. My attempt is as follows,
imdata = imread('dayonefile.tiff'); % imported array
removed = imdata(1:2048,1:2048); % scale etc. removed
white = removed>149; %values greater than 149 are true, less are false
pixels=imagesc(white,[0 1]); colormap(gray);%colormap image black is less than 150
m=0; for ii=1:2048 for jj=1:2048 if (removed(ii,jj))>149 m=m+1; end end end %total number of pixels with value greater than 149
r=0;%number of "kernals"
t=0;%group one
u=0;%group two
v=0;%group three
w=0;%group four
for ii=2:2047
for jj=2:2047
if ((removed(ii-1:ii+1,jj-1:jj+1))>(149))
r=r+1; %total number of "kernals" (blocks of nine with values greater than 149)
if r>0
Mean(r)=mean2(removed(ii-1:ii+1,jj-1:jj+1)); %Gives the mean of each "Kernal"
if ((174)>(Mean(r))>=(150)); %attempt to sort means
t=t+1;
elseif ((199)>(Mean(r))>=(175));
u=u+1;
elseif ((229)>(Mean(r))>=(200));
v=v+1;
else ((255)>(Mean(r))>=(230));
w=w+1;
end
end
end
end
end
This is my first program, and after one day I’m feeling pretty good about it. Once I fix my sorting problem I will be able to submit (as you can imagine I am pretty eager). Thanks in advance for everyone’s help!
Derek

답변 (1개)

Sean de Wolski
Sean de Wolski 2011년 5월 11일
if (all(all(removed(ii-1:ii+1,jj-1:jj+1)))>(149)) %added all(all(..P)
if ((174)>(mean(r)) && mean(r) >=(150)); %two conditions + && required
repeat as necessary for other if statements.

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by