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

2 views (last 30 days)
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);

Accepted Answer

Turlough Hughes
Turlough Hughes on 26 Jan 2020
Edited: Turlough Hughes on 27 Jan 2020
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 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!