How do i improve this loop?

3 ビュー (過去 30 日間)
charuleelaa vanilavarasu
charuleelaa vanilavarasu 2016 年 3 月 21 日
コメント済み: jgg 2016 年 3 月 22 日
[row column page] = size(Image3)
for i = row
for j = column
if Image3 (i, j, 1) > 350
if Image3 (i, j, 2) > 350
if Image3 (i, j, 3) > 350
Image3 (i, j, 1) = 0.0;
Image3 (i, j, 2) = 0.0;
Image3 (i, j, 3) = 0.0;
end
end
end
end
end
I tried this:
mask = Image3(:,:,1)>350 & Image3(:,:,2) > 350 & Image3(:,:,3) > 350;
Image3 = Image3 .* mask(:,:,[1 1 1]);
But it doesn't work. Just displays a black image. What am i doing wrong?

回答 (1 件)

jgg
jgg 2016 年 3 月 21 日
Your approach should work. Try this instead:
Image3 = randn(10,10,3)+355; %example data
mask = Image3(:,:,1) > 350 & Image3(:,:,2) > 350 & Image3(:,:,3) > 350;
mask = repmat(mask,1,1,3);
Image3(mask) = 0.0;
  2 件のコメント
charuleelaa vanilavarasu
charuleelaa vanilavarasu 2016 年 3 月 21 日
Still doesn't work. This is what i get when i ran the above code.
jgg
jgg 2016 年 3 月 22 日
You need to post your code; this code works fine. You have something unexpected going on with your Image3 matrix. Are you sure it has anything in which those three criteria are met?

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by