Hi, i want to create a gray scale image in matlab so I write a matrix 5x7 lets say A=[0 0 0 0 0 0 0; 80 80 80 80 80 80 80;200 200 200 200 200 200 200; 110 110 110 110 110 110 110; 160 160 160 160 160 160 160;255 255 255 255 255 255 255] . Then i use the imshow command and I expect an image where every row has a different intensity, the first black, the last white and the others with intermediate values. Instead of that i get a picture where only the first row is black and the rest of them are white. what am i doing wrong?

 채택된 답변

Image Analyst
Image Analyst 2013년 11월 29일

2 개 추천

A is a double. Cast it to uint8:
imshow(uint8(A));
or else use [] if you want to keep A as a double:
imshow(A, []);

댓글 수: 7

maria
maria 2013년 11월 29일
thanks a lot, it worked :) but what is actually difference between double and uint8 ?
Image Analyst
Image Analyst 2013년 11월 29일
A double is a 8 byte (64 bit number) that can represent a wide range of numbers, including those of fractional values. A uint8 is a 1 byte (8 bit) number that represents only integers in the range of 0 to 255.
maria
maria 2013년 11월 30일
편집: maria 2013년 11월 30일
great, but even in that case matrix A has only integers. should't it be able to give me a grayscale image even though it's double?
Image Analyst
Image Analyst 2013년 11월 30일
편집: Image Analyst 2013년 11월 30일
It is a grayscale image - a floating point grayscale image. But it's not an integer class . It's a double class that happens to have only integers in it, but it's still a double. Look:
A=[0 0 0 0 0 0 0; 80 80 80 80 80 80 80;200 200 200 200 200 200 200; 110 110 110 110 110 110 110; 160 160 160 160 160 160 160;255 255 255 255 255 255 255]
whos A
A 6x7 336 double
maria
maria 2013년 12월 1일
but my matrix represents a filter, and i want to impose it in an image. should i convert it to uint8 or is it fine if it is double?
Image Analyst
Image Analyst 2013년 12월 1일
It's fine if it's a double. You'll get more accuracy that way. You only need to convert it to an integer if you want to do certain things, like store it in a standard image format.
maria
maria 2013년 12월 1일
oh ok, thank you so much for your help :)

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

질문:

2013년 11월 29일

댓글:

2013년 12월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by