이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Matlab imread grayscale import has bad contrast
조회 수: 1 (최근 30일)
이전 댓글 표시
I'm trying to import a series of grayscale TIFF images. The pixels span the full range of values, from pure white to pure black. This can be seen when the image is viewed in a desktop program such as paint. However, when imread in Matlab is used to import the image, the contrast is greatly reduced: instead of spanning from 0 to 255 like it ought to, it covers only 70 to 95, for example. The range is different for each imported file.
The image is definitely grayscale, as imread outputs a 2D matrix.
Is there some trick that needs to be used, so that the image has the proper contrast after import?
댓글 수: 17
Geoff Hayes
2014년 8월 13일
Jacob - could you attach one of the images that should be showing pure white and pure black colours, but is only covering a subset of the range?
Jacob
2014년 8월 13일
Actually I used Windows' "Remove Properties and Personal Information" tool in the file properties menu to remove anything sensitive and tried importing that and it works. Does Matlab have a way of removing file properties?
I'm sorry but I'd prefer not to upload the picture; my company takes IP very seriously.
Joseph Cheng
2014년 8월 13일
Then how about create a sample TIFF that you generate (non IP gradient, random pixel values, take Lena (or matlab sample image) and convert to problematic TIFF) that also contains this problem. Which property that you removed which caused this to import correctly?
Geoff Hayes
2014년 8월 13일
Interesting - I wonder what properties you removed? Could you do the following instead - on the tif file that has not had its properties removed, can you run the command
imfinfo('myTifWithProps.tif')
and compare those results with the file where you have removed all properties and personal info
imfinfo('myTifWithoutProps.tif')
Either or both might still show something sensitive, so if you'd rather not post, I understand.
Jacob
2014년 8월 13일
I already did just that. Both Windows' property viewer and imfinfo show identical results. Yet the stripped file definitely has the proper grayscale.
Geoff Hayes
2014년 8월 13일
t = Tiff('myTifWithProblems.tif','r');
image_one = t.read();
imshow(subimage_one)
Jacob
2014년 8월 13일
I get an elaborate structure from Tiff(). What am I looking for? t has the following fields. Each one except file name is a structure.
t.FileName, t.TagID, t.SubFileType, t.Compression, t.Photometric, t.Thresholding, t.Orientation, t.PlanarConfiguration, t.ExtraSamples, t.Group3Options, t.ResolutionUnit, t.InkSet, t.SampleFormat, t.YCbCrPositioning, t.SGILogDataFmt, t.JPEGColorMode
Jacob
2014년 8월 13일
The Tiff object returned by t = Tiff('image.tif','r') seems to be a directory of possible values rather than an actual list of properties.
imfinfo gives actual values for those fields but all of the data returned by imfinfo is the same before and after clearing the properties.
Geoff Hayes
2014년 8월 13일
I was curious to see what happened when the TIFF library was used to load and read the image.
Did
img = t.read();
imshow(img)
show the same flawed image?
Jacob
2014년 8월 13일
Ok I have no clue what happened but displaying the "stripped" file now has bad contrast just like the normal file. I have no clue what made it display properly before.
Geoff Hayes
2014년 8월 13일
What are the lines of code that you are using to read the file - simply imread('image.tif'), or something else? Do you have (or can you create) a non-sensitive file that is exhibiting this behaviour? And, are you doing anything special/different when generating the tif?
Jacob
2014년 8월 13일
What I'm doing right now as a workaround is I'll have the user manually convert the TIFFs to PNG in MSPaint. Matlab is displaying PNG's just fine with the help of the rgb2gray function. Obviously this is not ideal though so if you have any more insight that would be great.
I'm not sure what changed but the stripped TIFF displays wrong as well. I think I need to find some TIFF property that is improperly defining the luminance scale of the image.
Jacob
2014년 8월 13일
The tif is generated from a 3rd party program, which is why I'm trying to find something embedded in the file.
I think I found a way around. The program can also export to .csv, so if I can parse through that, it might be the way I have to go. I'm sorry if I wasted your time, I really thought TIFF files would be easier to process.
Geoff Hayes
2014년 8월 13일
If you do something like
[img,map] = imread('yourTifFile.tif');
is map empty?
Jacob
2014년 8월 14일
I'm just driven by curiosity now. The map is the same as what was stored under the Colormap property. 256x3 array ranging from 0 to 1. Seems to be divided into blocks of 24 rows where it would start at zero and either be all zeros for the next 24 rows; or start at zero and irregularly increase towards 1. For some reason, loading the image using imshow in the command line displays it properly without the contrast issue. I think I may still stick with csv but it's interesting that the TIFF worked in the command prompt.
Geoff Hayes
2014년 8월 14일
Jacob - so what happens if you do the following:
[img,map] = imread('yourTifFile.tif');
imshow(img);
At this point, is the image displaying the poor contrast? If so, then do the following
colormap(map)
What does the image look like now that you are using the colour map that is associated with the image?
Maybe the integers in the 2D img matrix are NOT colours but indices into the colour map that comes with the image.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)