Matlab Image() function is not displaying colors correctly

1 回表示 (過去 30 日間)
Ryan Gibbs
Ryan Gibbs 2018 年 4 月 27 日
編集済み: Walter Roberson 2018 年 4 月 27 日
I have created a 50x50 pixel matrix, in which each 'pixel' has been assigned 3 random values between 0 and 255. When I visualize the image using image(), a figure that is mostly white appears, and the colors that are shown are incorrectly represented. I examined some of the white pixels and saw that they did indeed have RGB values associated, and I know that the resulting color should not be white. The code I used to create the image is shown below. Any help would be greatly appreciated.
clear;
width = 50;
height = 50;
W = zeros(height,width,3);
for i=1:(height)
for j=1:(width)
W(i,j,1) = randi(256)-1;
W(i,j,2) = randi(256)-1;
W(i,j,3) = randi(256)-1;
end
end
I realized that I needed to normalize the RGB values.
  1 件のコメント
Stephen23
Stephen23 2018 年 4 月 27 日
編集済み: Stephen23 2018 年 4 月 27 日
@Ryan Gibbs: Putting "SOLVED" in the title does not help us: if you are satisfied that one of the answers resolves your question, then accept that answer.

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

採用された回答

Ameer Hamza
Ameer Hamza 2018 年 4 月 27 日
You need to convert it to uint8 from double. Also no need to use for loop. Following code will work more efficiently.
image(uint8(randi(256, 50, 50, 3)))

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by