필터 지우기
필터 지우기

IMWRITE writing all black pictures?

조회 수: 22 (최근 30일)
Lee
Lee 2017년 1월 23일
댓글: Walter Roberson 2017년 1월 24일
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
Stephen23
Stephen23 2017년 1월 23일
@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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Guillaume
Guillaume 2017년 1월 23일
편집: Guillaume 2017년 1월 23일
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
Lee
Lee 2017년 1월 24일
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 2017년 1월 24일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by