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

1 visualizzazione (ultimi 30 giorni)
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);

Risposta accettata

Turlough Hughes
Turlough Hughes il 26 Gen 2020
Modificato: Turlough Hughes il 27 Gen 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 Commenti
Turlough Hughes
Turlough Hughes il 26 Gen 2020
You can just use im2uint8 in a similar fashion, see the following documentation.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Convert Image Type in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by