3 回答
TA贡献1827条经验 获得超8个赞
figurepic = imread('EcyOd.jpg');for mm = 1:size(pic,1)
for nn = 1:size(pic,2)
if pic(mm,nn,1) < 80 || pic(mm,nn,2) > 80 || pic(mm,nn,3) > 100
gsc = 0.3*pic(mm,nn,1) + 0.59*pic(mm,nn,2) + 0.11*pic(mm,nn,3);
pic(mm,nn,:) = [gsc gsc gsc];
end
endendimshow(pic)TA贡献1852条经验 获得超1个赞
rgb2hsvhsv2rgb:
cdata = imread('EcyOd.jpg'); % Load imagehsvImage = rgb2hsv(cdata);
% Convert the image to HSV spacehPlane = 360.*hsvImage(:, :, 1); % Get the hue plane scaled from 0 to 360sPlane = hsvImage(:, :, 2);
% Get the saturation planenonRedIndex = (hPlane > 20) & ... % Select "non-red" pixels
(hPlane < 340);sPlane(nonRedIndex) = 0;
% Set the selected pixel saturations to 0hsvImage(:, :, 2) = sPlane;
% Update the saturation planergbImage = hsv2rgb(hsvImage);
% Convert the image back to RGB space
关于选择颜色范围的注意事项.。
hPlanehistchistcountsbar:
binEdges = 0:360; % Edges of histogram binshFigure = figure();
% New figure% Bin pixel hues and plot histogram:if verLessThan('matlab', '8.4')
N = histc(hPlane(:), binEdges); % Use histc in older versions
hBar = bar(binEdges(1:end-1), N(1:end-1), 'histc');else
N = histcounts(hPlane(:), binEdges);
hBar = bar(binEdges(1:end-1), N, 'histc');endset(hBar, 'CData', 1:360, ... % Change the color of the bars using
'CDataMapping', 'direct', ... % indexed color mapping (360 colors)
'EdgeColor', 'none'); % and remove edge coloringcolormap(hsv(360));
% Change to an HSV color map with 360 pointsaxis([0 360 0 max(N)]);
% Change the axes limitsset(gca, 'Color', 'k');
% Change the axes background colorset(hFigure, 'Pos', [50 400 560 200]);
% Change the figure sizexlabel('HSV hue (in degrees)');
% Add an x labelylabel('Bin counts');
% Add a y labelTA贡献1786条经验 获得超13个赞
red = cdata( y, x, 1 );
green = cdata( y, x, 2 );
blue = cdata(y, x, 3);
if (red < (blue * 1.4) || red < (green * 1.4) )
{
avg = (red + green + blue) / 3;
cdata(y, x, 1) = avg;
cdata(y, x, 2) = avg;
cdata(y, x, 3) = avg;
}添加回答
举报
