What is the formula to convert uint8 image to double format ?

49 ビュー (過去 30 日間)
Pramod Bhat
Pramod Bhat 2011 年 8 月 19 日
Hi friends, i want to convert a uint8 format image to double format.I have got command 'im2double' for that. But i want to know the basic formula for converting that.
For ex : i want to represent intensity level 256 to double format which is represented in [0 1]. please help. Thanks...

回答 (3 件)

Friedrich
Friedrich 2011 年 8 月 19 日
Hi,
simply cast it as double and than divide by the maximum number of the datatype. In your case (uint8) its 255. So when your image is A do
double(A)/255
or more general
double(A)/intmax(class(A))
  3 件のコメント
Friedrich
Friedrich 2011 年 8 月 19 日
Yes im2double does that but Pramod asked for the basic formula. He knows about im2double.
Fangjun Jiang
Fangjun Jiang 2011 年 8 月 19 日
Fair enough! No argument from me!

サインインしてコメントする。


Fangjun Jiang
Fangjun Jiang 2011 年 8 月 19 日
By simply dividing all the numbers by 255?
See example:
I1 = reshape(uint8(linspace(1,255,25)),[5 5])
I2 = im2double(I1)
  3 件のコメント
Fangjun Jiang
Fangjun Jiang 2011 年 8 月 19 日
What do you mean? The code I quoted is from help im2double. The OP is asking how im2double is able to convert 0~255 to 0~1. I am guessing it just divides by 255, like you guessed.
Friedrich
Friedrich 2011 年 8 月 19 日
My comment is related to your statement: "By simply dividing all the numbers by 255?" Simply diving is not enough you have to cast first.

サインインしてコメントする。


Pramod Bhat
Pramod Bhat 2011 年 8 月 19 日
Thanks alot friends. ..). thanq. i understood.

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by