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 CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by