You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Quantize 3 colors and detect black square color as the one that isn't white or black (max and min color norm). Find a pixel with such color in the image.
Quantize 8 colors. Get the color of the pixel above and change it to red.
Matlab:
% process image
function chess_util( fin, fout )
% read
a = imread( fin );
assert( size( a, 3 ) == 3 );
% quantize colors
[ia, cm] = rgb2ind( a, 3, 'nodither' ); % 3, 4
%imshow( ia, cm )
% impixelinfo()
% colormapeditor
% change color
if 1
% visualize color map
if 0
rgbplot(cm)
hold on
colormap(cm)
colorbar('Ticks',[])
hold off
end
% find dark square color in color map
% eliminate black and white
ii = 1:size( cm, 1 ); % candidates
dd = sum( cm.^2, 2 );
[~, imin] = min( dd(ii) ); % black
ii(imin) = [];
[~, imin] = min( -dd(ii) ); % white
ii(imin) = [];
[~, imin] = min( dd(ii) ); % darkest
icl = ii(imin);
%cl = cm( icl, :);
[row, col] = find( ia == icl - 1 ); % find a pixel with that value
% load more colors
[ia, cm] = rgb2ind( a, 8, 'nodither' );
icl = ia( row(1), col(1) ); % get color from pixel location
cm(icl + 1, :) = [1, 0, 0]; % change
end
% write
imwrite( ia, cm, fout );
end
The text was updated successfully, but these errors were encountered: