Normalizing RGB coordinates in an image
Show older comments
I've tried to make a program to separate and normalize the colors of an image, and made the following code.
The intention is to make a binary image from the green one. But all my color-normalized images appear entirely black.
Would someone please help me figure out whats wrong?
%separating colors:
grassimg=imread('grass.jpg');
colorimgR=grassimg(:,:,1);
colorimgG=grassimg(:,:,2);
colorimgB=grassimg(:,:,3);
%All these images appeares in different kind of greyscales.
%Thresholding the "green" image:
thresh_green = colorimgG >100;
figure(2)
rez_threshg = imresize(thresh_green, 0.5);
imshow(rez_threshg)
%I get a quite ok binary image.
%Normalizing colors (this is what turns out wrong):
allcolors = colorimgR+colorimgG+colorimgB;
redimg = colorimgR./allcolors;
greenimg = colorimgG./allcolors;
blueimg = colorimgB./allcolors;
figure(3)
subplot(1,3,1);
imshow(redimg)
subplot(1,3,2);
imshow(greenimg)
subplot(1,3,3);
imshow(blueimg)
%All these single-colored images turnes out black
%Obviously it does'nt work to binarize a black image... :
threshGimg = greenimg > 100;
figure(4)
rez_greenimg = imresize(greenimg, 0.5);
imshow(rez_greenimg)
Accepted Answer
More Answers (0)
Categories
Find more on Modify Image Colors in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!