converting floating point value to integer

I have an image in floating point value,i have to convert it into integer ,can anyone suggest an idea please
I have values for example ,i have taken some pixels from my image,and my whole image pixels values in these ranges only,now i want to convert this floating point into an integer value and i want to read image from those intteger value pixels
0.0004 0.0004 0.0004 0.0003 0.0003 0.0002
0.0006 0.0005 0.0005 0.0005 0.0004 0.0003
0.0008 0.0007 0.0007 0.0007 0.0006 0.0005

6 件のコメント

Jan
Jan 2011 年 12 月 14 日
I've tried to answer, but this question misses an important point: What do you want as output exactly? The input seems to be a 16-bit grey-scale image. You can convert it to the type UINT8 or UINT16. You can scale it such that the smallest value of the input gets 0, or simply multiply all data by 2^8 or 2^16. You could spread the values, such that the complete range from 0 to 2^8-1 (or 2^16-1) is used.
Before I start to guess, what you want, or present a bunch of solutions, it is more efficient to let you specify your needs.
kash
kash 2011 年 12 月 14 日
from these values i am not getting an image ,i get only black colour,so want to convert to integer to get image,as u said can u tell how to scale it ,i tried uint8(image),even then i get same black colour
Jan
Jan 2011 年 12 月 14 日
@kash: Of ocurse uint8(0.0004) replies the same as uint8(0.0007). Simply try it in the command window.
Let me ask again: What is the range of the inputs and waht range do you want as output. Please be as specific as possible - guessing what you want wastes our and your time.
kash
kash 2011 年 12 月 14 日
Jan i have processed an operation,now my image is black in colour,what should be done to get that output image
Jan
Jan 2011 年 12 月 14 日
And again: What is the range of the input (max value - min value) and what is the wanted range for the output?
kash
kash 2011 年 12 月 14 日
max val=5.2967e-004
min val=4.1036e-012
the output range is 0-255

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

 採用された回答

Andrei Bobrov
Andrei Bobrov 2011 年 12 月 14 日

0 投票

A = [ 0.0004 0.0004 0.0004 0.0003 0.0003 0.0002
0.0006 0.0005 0.0005 0.0005 0.0004 0.0003
0.0008 0.0007 0.0007 0.0007 0.0006 0.0005]
[a b c] = unique(A);
B = im2uint8(linspace(0,1,numel(a)))
out = reshape(B(c),size(A))
imagesc(out)
ADD
B = linspace(0,1,numel(a))
out = reshape(B(c),size(A))
image(bsxfun(@plus,out,zeros(1,1,3)))

4 件のコメント

kash
kash 2011 年 12 月 14 日
Andrei as per your code my values gets chanded in to 255,and i am getting green coloured image
Andrei Bobrov
Andrei Bobrov 2011 年 12 月 14 日
http://imageshack.us/photo/my-images/24/im1j.png/
kash
kash 2011 年 12 月 14 日
thanks andrei
kash
kash 2011 年 12 月 14 日
Andrei can u tell hoe electromagnetism algorithm works with image processing please

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

その他の回答 (1 件)

Jan
Jan 2011 年 12 月 14 日

0 投票

A = [0.0004 0.0004 0.0004 0.0003 0.0003 0.0002;
0.0006 0.0005 0.0005 0.0005 0.0004 0.0003;
0.0008 0.0007 0.0007 0.0007 0.0006 0.0005];
B = uint8((A - min(A(:))) * (255 / (max(A(:) - min(A(:))))));

カテゴリ

ヘルプ センター および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by