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

조회 수: 1 (최근 30일)
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