MATLAB Answers

i did some changes in red,green,blue channel of the image .Now when is am using cat function it is giving me full white image.This is not the output i want

1 view (last 30 days)
M Manohar prabhu
M Manohar prabhu on 15 Jan 2020
Edited: M Manohar prabhu on 16 Jan 2020
image=imread("57_img_.png");
subplot(2,1,1);imshow(image);
[R,C,~]=size(image);
%disp(R);
%disp(C);
Red=image(:,:,1);
Green=image(:,:,2);
Blue=image(:,:,3);
red=0;
green=0;
blue=0;
g=sum(Red(:));
e=sum(Green(:));
f=sum(Blue(:));
[r,c]=size(Blue);
red_avg=g/(R*C);
disp(red_avg);
green_avg=e/(R*C);
disp(green_avg);
blue_avg=f/(R*C);
disp(blue_avg);
avg=(red_avg+green_avg+blue_avg)/3;
disp(avg);
new_red = zeros(size(Red));
for i=1:R
for j=1:C
pixel_red=(double(Red(i,j))*avg)/red_avg;
new_red(i,j)=pixel_red;
end
end
%disp(new_red(1,1));
disp(new_red);
%subplot(6,1,1);imshow(new_red,[]);
new_green = zeros(size(Green));
for i=1:R
for j=1:C
pixel_green=(double(Green(i,j))*avg)/green_avg;
new_green(i,j)=pixel_green;
end
end
%disp(new_green);
%subplot(6,1,2);imshow(new_green,[]);
new_blue = zeros(size(Blue));
for i=1:R
for j=1:C
pixel_blue=(double(Blue(i,j))*avg)/blue_avg;
new_blue(i,j)= pixel_blue;
end
end
%subplot(6,1,3);imshow(new_blue,[]);
%subplot(6,1,4);imshow(Red);
%subplot(6,1,5);imshow(Green);
%subplot(6,1,6);imshow(Blue);
%disp(new_blue);
%imshow(new_blue);
%imshow(new_red);
%new_red1=round(new_red,0);
%new_green1=round(new_green,0);
%new_blue1=round(new_blue,0);
new_img=(cat(3,new_red,new_green,new_blue));
subplot(2,1,2);imshow(new_img);

Accepted Answer

darova
darova on 15 Jan 2020
You have white image because of format. Try
imshow(uint8(new_img));
your code can be shorter (no for loop needed)
image=imread('732_img_.png');
[m,n,~] = size(image);
Red=image(:,:,1);
Green=image(:,:,2);
Blue=image(:,:,3);
red_avg = mean(Red(:));
green_avg = mean(Green(:));
blue_avg = mean(Blue(:));
avg = mean(image(:));
disp(red_avg);
disp(green_avg);
disp(blue_avg);
disp(avg);
new_red = avg/red_avg*Red;
new_green = avg/green_avg*Green;
new_blue = avg/blue_avg*Blue;
new_img=cat(3,new_red,new_green,new_blue);
imshow([image new_img])

More Answers (0)

Sign in to answer this question.


Translated by