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 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by