The output matrix values are either 0 or 1 but i want it between [0,1]

1 回表示 (過去 30 日間)
M Manohar prabhu
M Manohar prabhu 2020 年 1 月 26 日
編集済み: Turlough Hughes 2020 年 1 月 27 日
image=imread("101_img_.png");
[R,C,~]=size(image);
Red=image(:,:,1);
Green=image(:,:,2);
Blue=image(:,:,3)
red_norm=zeros(size(Red));
red_norm=(Red - min(Red(:)))./(max(Red(:))-min(Red(:)));
green_norm=zeros(size(Green));
green_norm=(Green - min(Green(:)))./(max(Green(:))-min(Green(:)));
red_norm_sum=sum(red_norm(:));
disp(green_norm);

採用された回答

Turlough Hughes
Turlough Hughes 2020 年 1 月 26 日
編集済み: Turlough Hughes 2020 年 1 月 27 日
When you load in the image the data type is uint8 - unsigned 8 bit integers. So you can't get values between 0 and 1 unless you change the data type:
I = imread('101_img_.png');
I = im2double(I);
Your following calculations should go as expected now:
[R,C,~]=size(I);
Red = I(:,:,1);
Green = I(:,:,2);
Blue = I(:,:,3);
red_norm = zeros(size(Red));
red_norm = (Red - min(Red(:)))./(max(Red(:))-min(Red(:)));
green_norm = zeros(size(Green));
green_norm = (Green - min(Green(:)))./(max(Green(:))-min(Green(:)));
red_norm_sum = sum(red_norm(:));
  3 件のコメント
Turlough Hughes
Turlough Hughes 2020 年 1 月 26 日
You can just use im2uint8 in a similar fashion, see the following documentation.
Turlough Hughes
Turlough Hughes 2020 年 1 月 26 日
Anything else? If not can you accept the answer.

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by