image to binary issues

3 visualizaciones (últimos 30 días)
jchris14
jchris14 el 23 de Oct. de 2014
Comentada: jchris14 el 23 de Oct. de 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

Respuesta aceptada

Guillaume
Guillaume el 23 de Oct. de 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 comentarios
Image Analyst
Image Analyst el 23 de Oct. de 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 el 23 de Oct. de 2014
Thank you for the help. I will use them.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Image Processing Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by