Image processing help. Multiplication of Images gives different results at Unit16, unit 32, unit 8.

2 ビュー (過去 30 日間)
[EDIT: 20110611 23:32 CDT - reformat - WDR]
Codes :
a=imread('b.jpg');b=imread('c.jpg');c=a.*b;imshow(c)
a1=uint16(a);b1=uint16(b);c1=a1.*b1;imshow(c1)
a2=uint32(a);b2=uint32(b);c2=a2.*b2;imshow(c2)
I am not sure how to upload the picture I am using. I will let you know the problem now.
I am trying to 2 images. a and b.
1) Using unit 8 , I get some distortions.
2) Using unit 16, I am getting the required image.
3) Using unit 32, I am getting a complete black image.
Please let me know the problem. My friend needs this for her project. She asked me, I am not sure what is the problem. Please reply. Thank you.

採用された回答

Walter Roberson
Walter Roberson 2011 年 6 月 12 日
Check
class(a)
class(b)
I suspect you will find that your images are uint16, but uint8 could be possible as well.
To understand the distortion you get with uint8, take a look at this result:
>> uint8(2)*uint8(128)
ans =
255
Why 255 instead of 256? To understand this, read the documentation
To understand about getting the black image, read this image documentation in particular the section "True Color Images"
  3 件のコメント
Walter Roberson
Walter Roberson 2011 年 6 月 12 日
The documentation I pointed to indicates:
===
The uint8 function maps any values in array that are outside the limit to the nearest endpoint. For example,
uint8(2^8) % 2^8 = 256
returns
ans =
255
===
This example uses exponentiation but the same thing happens with multiplication. Unless your values are restricted to 15 or less in the original image, when you multiply two of them you might end up with a value that is at least 16*16=256 which is "outside the limit" and will be mapped to "the nearest endpoint" (i.e., 255)
For the black image, refer to the second bit of documentation I indicated:
===
If you want to convert a true color image from one data type to the other, you must rescale the data. For example, this statement converts a uint8 true color image to double.
RGB64 = double(RGB8)/255;
or for uint16 images,
RGB64 = double(RGB16)/65535;
This statement converts a double true color image to uint8:
RGB8 = uint8(round(RGB64*255));
or to obtain uint16 images, type
RGB16 = uint16(round(RGB64*65535));
vj
vj 2011 年 6 月 13 日
hey thx Walter. I am checking on that. I will get back to you for any clarifications...

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

その他の回答 (1 件)

Alex Taylor
Alex Taylor 2011 年 6 月 13 日
Hi Vijay,
Walter's answer is accurate. I just wanted to add that since you have the Image Processing Toolbox, you might look at the Image Processing functions im2uint16 and im2uint32.
Unlike the MATLAB casting functions Walter used, the Image Processing Toolbox conversion functions manage both the casting and rescaling of your data when moving to other datatypes.
doc im2uint16

カテゴリ

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