image read and write problem

조회 수: 13 (최근 30일)
Weia Reinboud
Weia Reinboud 2020년 7월 13일
이동: DGM 2023년 2월 20일
Sometimes imwrite and imread work OK, but often not. In that case in stead of numbers between 0 and 255 (RGB tif file) all numbers become 0 or 255. Nothing in between. I can't find a problem and I can't find a system in what's going wrong. Any hints? You can see in the picture waht happens. It's a very tiny tif-file, all code you can see and after write and read it's damaged. Only red shown, blue and green the same.
  댓글 수: 7
Weia Reinboud
Weia Reinboud 2020년 7월 14일
Then continued with imwrite, imread again and the file had become binary, only numbers 0 and 255 and nothing in between. Like the screen picture above.
Strange is that sometimes this test worked and sometimes not.
Weia Reinboud
Weia Reinboud 2020년 7월 14일
The class of the file, I do not know. Just a tif from Photoshop.

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

채택된 답변

Walter Roberson
Walter Roberson 2020년 7월 14일
srijf2(:,:,1)=[173,173,173,173,173,173,173,173
0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0
38,38,38,138,38,38,38,38
255,255,255,255,255,255,255,255
255,255,255,255,255,255,255,255]
That creates double precisions numbers, class double(). When you imwrite() data that is class double() then it assumes the dynamic range is 0 (black) to 1 (full intensity), and scales and converts to uint8, like uint8(srijf2 * 255) . Because of saturation of the uint8 range, that is going to give you all 0 or 255.
Do not double() integer images unless you know exactly what you are doing. Use im2double() if you need to convert from integer images to double precision images.
  댓글 수: 15
Image Analyst
Image Analyst 2020년 7월 21일
이동: DGM 2023년 2월 20일
No, you should have done
cupoltje = uint8(cupoltje); % or cupoltje = uint8(255 * mat2gray(cupoltje));
NOT
cupoltje=single(cupoltje); % Single won't work.
Not sure why you did that when we and MATLAB have already told you single won't work. Why didn't you convert to uint8?
Weia Reinboud
Weia Reinboud 2020년 7월 21일
이동: DGM 2023년 2월 20일
It works! (I don't see in the above where this same conversion is given.)

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by