フィルターのクリア

image to binary issues

1 回表示 (過去 30 日間)
jchris14
jchris14 2014 年 10 月 23 日
コメント済み: jchris14 2014 年 10 月 23 日
Hi,
i want to run a single image through multiple thresholds. Initially, i had separate lines of code for each threshold (im2bw(img,.1), im2bw(img,.2) and so on). Now i want to run the image between thresholds ranging from 0:.001:.5. thats a total of 500 hundred values. How do I write that in few lines rather than write 500 lines?
I have tried for loop
thld = 0 : .001 : .5
for i=1:500
a(i)=im2bw(img,thld)
end
but this doesn't work.
Thank you for the help

採用された回答

Guillaume
Guillaume 2014 年 10 月 23 日
Nearly there. Use cell arrays for storing your images or a 3d matrix:
thld = 0 : .001 : .5;
for idx = 1:numel(thld)
a{idx} = im2bw(img, thld(idx));
end
or
thld = 0 : .001 : .5;
a = zeros([size(img), numel(thld)]); %better preallocate huge array
for idx = 1:numel(thld)
a(:,:, idx) = im2bw(img, thld(idx));
end
  8 件のコメント
Image Analyst
Image Analyst 2014 年 10 月 23 日
Yep, like I said, the badly-named "a" is the culprit. It's a string just like I said. Did you use imread() like I suggested in my prior comment? No, not in that code you just posted. Why don't you use my suggestion? It will be alright then if you do.
jchris14
jchris14 2014 年 10 月 23 日
Thank you for the help. I will use them.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by