how to convert unit8 type images to logical type

if true
myFolder = 'E:\\inverted\\i1';
for PicNum = 100:-1:1;
fullFileName = fullfile(myFolder,sprintf('%d.bmp',PicNum));
fprintf(1, 'Now reading %s\n', fullFileName);
imageArray{PicNum}=imread(fullFileName);
logical(imageArray{PicNum});//here im trying to convert my images to logical but its not happening
imshow(imageArray{PicNum}); % Display image.
end
end

 Respuesta aceptada

Image Analyst
Image Analyst el 16 de Feb. de 2015
To convert a gray level image to a logical binary image you must threshold:
binaryImage = grayImage > someValue;

4 comentarios

neha viswanath
neha viswanath el 16 de Feb. de 2015
my images are already converted to logical .but in the above code im getting a cell named imageArray which has 100 unit8 type 50*50 size images.so i used logical() to convert them to 0-1 type.but its not working.now i need to convert every unit8 to logical.
Image Analyst
Image Analyst el 16 de Feb. de 2015
Editada: Image Analyst el 16 de Feb. de 2015
The images are NOT already logical. They may have gray levels of only 0 and 1 or of only 0 and 255 but after you use imread() they are not logical - that's why you're trying to convert them. If I assume you just have the two gray levels, then you can do this:
logicalImage = imageArray{PicNum} ~= 0;
logicalImage here will truly be a logical image with values of true and false, not 0 and 255 or whatever. Then proceed to analyze or process logicalImage in whatever way you need to.
neha viswanath
neha viswanath el 16 de Feb. de 2015
thankyou sir
sir,I need to access each image in cell array.
if true
for i=1:1:100
feature_extractor(logicalImage{i});
end
end
so i could get features of all the images in 'ans'.with the above code i could not accomplish my task.can you please help me out.

Iniciar sesión para comentar.

Más respuestas (1)

Adam
Adam el 16 de Feb. de 2015
Editada: Adam el 16 de Feb. de 2015
imageArrayLogical = cellfun( @(im) logical(im), imageArray, 'UniformOutput', false );
or you can just do it in a for loop if you prefer. Note the result is still a cell array of your data so you still have to index into it using cell notation.

Categorías

Más información sobre Images en Centro de ayuda y File Exchange.

Preguntada:

el 16 de Feb. de 2015

Comentada:

el 17 de Feb. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by