image to binary issues

3 Ansichten (letzte 30 Tage)
jchris14
jchris14 am 23 Okt. 2014
Kommentiert: jchris14 am 23 Okt. 2014
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

Akzeptierte Antwort

Guillaume
Guillaume am 23 Okt. 2014
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 Kommentare
Image Analyst
Image Analyst am 23 Okt. 2014
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 am 23 Okt. 2014
Thank you for the help. I will use them.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by