How to I convert a binary (logical) image back into double, uint8, etc, without changing what the image looks like in binary?
65 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Rowan Quintero
am 26 Jul. 2023
Kommentiert: Rowan Quintero
am 27 Jul. 2023
I took a grayscale image (.tif file) and converted it into binary using imbinarize(). This gave me the desired visual, but now I want to save that visual and use it for processing. The issue is that my processing method does not take logical inputs and I can not change it. Is there a way to perserve the binary visual and convert it into a double or uint8? I could just screenshot it then convert it to .tif, but that would be cheaty. Thank you!
0 Kommentare
Akzeptierte Antwort
DGM
am 26 Jul. 2023
Bearbeitet: DGM
am 26 Jul. 2023
If you want to change the numeric class of an image while retaining the image scale with respect to black/white, you normally use tools like im2uint8(), im2double(), etc. Those will also work on logical class images, where logical values become the class-dependent black/white values. For example:
A = logical([0 1 1 0]) % my logical image
B = im2uint8(A) % represented in uint8
C = im2double(A) % represented in double
Depending on the file format you're saving to, this conversion may be done automatically if you pass a logical array to imwrite(), though formats such as PNG will support logical arrays, so you may choose to use im2uint8() beforehand in such a case.
Without knowing what subsequent processing is going to happen, bear in mind that while the logical and uint8 representations both contain the same information and will be rendered identically, they may not be compatible with the same operations.
For instance, you couldn't use the uint8 image directly for logical indexing
outpict = inpict(A); % this is basic logical indexing using a mask
outpict = inpict(B); % but this will result in an error
Also, you can imagine other scenarios where they wouldn't be equivalent due to the change in scale.
outpict = inpict.*A; % this wouldn't be implausible, since A is unit-scale
outpict = inpict.*B; % but this would result either in an error or an improperly-scaled result
Weitere Antworten (1)
Walter Roberson
am 26 Jul. 2023
img = imbinarize(imread('cameraman.tif'));
imshow(img); title('logical')
i8 = im2uint8(img);
imshow(i8); title('uint8');
id = im2double(img);
imshow(id); title('double');
Siehe auch
Kategorien
Mehr zu Convert Image Type 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!