Hi,
I'm doing some math calculations in a code. I noticed something strange in the code below:
a = imread('C:\tqPixels.png'); I = rgb2gray(a);
exp = I.^2
As tqPixels.png is an image with only 4 white pixels (all have 255 value), I thought that exp variable value would be each value powered to itself (255 * 255):
exp = [65025, 65025; 65025, 65025]
However, when I saw exp value in the results, it had the same values variable "I" had:
exp = [255, 255; 255, 255]
Sorry if this is very simple, but why .^2 does not work as it should?
I'm attaching the image and the code here for you to test. I really appreciate any suggestions on this.
a = imread('C:\tqPixels.png');
I = rgb2gray(a);
exp1 = I.^2;

 채택된 답변

Roger Stafford
Roger Stafford 2016년 6월 17일

1 개 추천

I think you need to convert I to ‘double’ before doing the exponentiation on it. As it is, I believe it is ‘uint8’ type and anything above 255 is set down to just 255. Do this:
exp1 = double(I).^2

댓글 수: 4

Image Analyst
Image Analyst 2016년 6월 17일
Note how Roger doesn't use exp for the variable name like you did. exp is a built-in function and you should not use it as a variable name.
Steven Lord
Steven Lord 2016년 6월 17일
This saturation behavior is described in the "Largest and Smallest Values for Integer Classes" section on this documentation page.
Queila Martins
Queila Martins 2016년 6월 17일
That's true, Image Analyst (about variable's name). Thank you for pointing that :D
Also thank you Steven for the link. Very useful!!
Queila Martins
Queila Martins 2016년 6월 17일
Roger, it worked! Now it makes sense. Thank you so much!

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

추가 답변 (0개)

카테고리

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

질문:

2016년 6월 17일

댓글:

2016년 6월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by