Borrar filtros
Borrar filtros

IMWRITE writing all black pictures?

22 visualizaciones (últimos 30 días)
Lee
Lee el 23 de En. de 2017
Comentada: Walter Roberson el 24 de En. de 2017
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 comentario
Stephen23
Stephen23 el 23 de En. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Guillaume
Guillaume el 23 de En. de 2017
Editada: Guillaume el 23 de En. de 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 comentarios
Lee
Lee el 24 de En. de 2017
Sorry it's taken so long to answer you back. I've been in class all day. The exact command i'm using is imwrite('file','filename','tif'). So I assumed it would write automatically to uint16.
So, to answer your question, how am I veiwing the image? It's actually a table of pixel values "I think". I say I think because what i'm doing is extracting some data from a .C01 file extension and getting these values. If i use the command imagesc(.....) with the matrix of values, it shows the correct image. I have thousands of these images though and I need to write all of them to .tif files so I can review them.
Walter Roberson
Walter Roberson el 24 de En. de 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

Iniciar sesión para comentar.

Categorías

Más información sobre Images en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by