IMWRITE writing all black pictures?
22 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I've looked at the documentation for this but I'm clearly missing something. The highest rated answer according to google on MATLAB Answers was to perform
A = A - min(A(:));
A = A/max(A(:));
However, when I do this, my values are all 0. The data I'm using for imwrite is characterized as a 512x512 uint16 variable.
1 Commento
Stephen23
il 23 Gen 2017
@Lee: please edit your question and upload a sample array by clicking the paperclip button. Also show us exactly the code that you are using so that we can replicate the problem.
Risposte (1)
Guillaume
il 23 Gen 2017
Modificato: Guillaume
il 23 Gen 2017
Not many format support uint16 images. The only ones available to imwrite are JPEG, PNG and TIFF. Support for reading and displaying 16 bit images is also variable. Since most displays are only 8 bits, viewers have to convert the 16 bits to 8. Some viewers may do that by only displaying the low bits, other the high bits, which depending on the image may result in everything black (or white). So how are you viewing the image?
To be safe you could convert the image to 8 bits (or double, but imwrite will then convert it to 8 bits):
imwrite(im2uint8(yourimage), somefile);
%or
imwite(im2double(yourimage), somefile);
Of course, by converting to 8 bit you're dividing your dynamic range by 256.
edit: the reason your A = (A - min(A(:))) /max(A(:)) produces all zero is because you're doing integer division. You need to convert both numerators and denominators to double before dividing:
A = double(A - min(A(:))) / double(max(A(:))
2 Commenti
Walter Roberson
il 24 Gen 2017
minA = min(A(:));
A = double(A - minA) ./ double( max(A(:)) - minA );
The result will be in the range 0 to 1. When you imwrite() that, imwrite() will see that it is floating point data and will automatically do im2uint8() and write the resulting 8 bits per channel image
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!