cohist session 2
filename = 'flowers4.png'; % filename = 'color_cube.jpg'; rgb = imread(filename); rgb = im2double(rgb); imshow(rgb);

uncomment for interactive specification get sample of background color
% [samp rect] = imcrop; % save sess2 samp rect load sess2 imshow(samp);

xc = samp(:,:,1) - 0.5*(samp(:,:,2)+samp(:,:,3)); yc = sqrt(3)/2*(samp(:,:,2)-samp(:,:,3)); zc = (samp(:,:,1)+samp(:,:,2)+samp(:,:,3))/3; subplot(2,2,1); imshow(samp); subplot(2,2,2) cohist((xc+1)/2,(yc+1)/2); xlabel('chroma x'); ylabel('chroma y'); subplot(2,2,3); cohist(zc,(xc+1)/2); xlabel('value'); ylabel('chroma x'); subplot(2,2,4); cohist(zc,(yc+1)/2); xlabel('value'); ylabel('chroma y');

close hist = imhist((xc+1)/2); % y = func1(hist); sx = sort(xc(:)); y(1) = sx(10); y(2) = sx(end-9); fprintf('chroma x range: %g %g\n',y); xd = rgb(:,:,1) - 0.5*(rgb(:,:,2)+rgb(:,:,3)); % use xc below to just look at selected region bw1 = and(xd>y(1),xd<y(2)); sz = size(bw1); %fprintf('%g included\n',sum(sum(bw1))/(sz(1)*sz(2))); imshow(~bw1);
chroma x range: -0.231373 0.196078

hist = imhist((yc+1)/2); % y = func1(hist); sy = sort(yc(:)); y(1) = sy(10); y(2) = sy(end-9); fprintf('chroma y range: %g %g\n',y); yd = sqrt(3)/2 * ( rgb(:,:,2) - rgb(:,:,3)); % use yc below to just look at selected region bw2 = and(yd>y(1),yd<y(2)); sz = size(bw2); % fprintf('%g included\n',sum(sum(bw2))/(sz(1)*sz(2))); imshow(~bw2);
chroma y range: 0.0509427 0.516219

imshow(~(bw1&bw2));

bw = ~(bw1&bw2); imshow(cat(3,rgb(:,:,1).*bw,rgb(:,:,2).*bw,rgb(:,:,3).*bw));
