第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何將RGB圖像轉(zhuǎn)換為灰度,但保留一種顏色?

如何將RGB圖像轉(zhuǎn)換為灰度,但保留一種顏色?

如何將RGB圖像轉(zhuǎn)換為灰度,但保留一種顏色?我試圖創(chuàng)造一個(gè)類似于罪惡之城或其他電影,他們刪除所有的顏色,但一個(gè)從圖像中刪除。我有一個(gè)RGB圖像,我想轉(zhuǎn)換為灰度,但我想保留一種顏色。這是我的照片:我想保留紅色。剩下的應(yīng)該是灰階的。到目前為止,這就是我的代碼輸出的內(nèi)容(您可以看到這些區(qū)域是正確的,我不知道為什么它們是白色的,而不是紅色的):到目前為止,這是我的代碼:filename = 'roses.jpg';[cdata,map] = imread( filename );% convert to RGB if it is indexed imageif ~isempty( map )     cdata = idx2rgb( cdata, map ); end%imtool('roses.jpg');imWidth = 685;imHeight = 428;% RGB ranges of a color we want to keepredRange     = [140 255];greenRange = [0 40];blueRange = [0 40];% RGB values we don't want to convert to grayscaleredToKeep =      zeros(imHeight, imWidth);greenToKeep = zeros(imHeight, imWidth);blueToKeep = zeros(imHeight, imWidth);for x=1:imWidth     for y=1:imHeight         red = cdata( y, x, 1 );         green = cdata( y, x, 2 );         blue = cdata( y, x, 3 );         if (red >= redRange(1) && red <= redRange(2) && green >= greenRange(1) && green <= greenRange(2) && blue >= blueRange(1) &         & blue <= blueRange(2))             redToKeep( y, x ) = red;             greenToKeep( y, x ) = green;             blueToKeep( y, x ) = blue;         else             redToKeep( y, x ) = 999;             greenToKeep( y, x ) = 999;             blueToKeep( y, x ) = 999;         end     end end im = rgb2gray(cdata);[X, map] = gray2ind(im);im = ind2rgb(X, map);for x=1:imWidth     for y=1:imHeight         if (redToKeep( y, x ) < 999)             im( y, x, 1 ) = 240;         end         if (greenToKeep( y, x ) < 999)             im( y, x, 2 ) = greenToKeep( y, x );         end         if (blueToKeep( y, x ) < 999)             im( y, x, 3 ) = blueToKeep( y, x );         end     end end imshow(im);
查看完整描述

3 回答

?
慕仙森

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個(gè)贊

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)


查看完整回答
反對(duì) 回復(fù) 2019-07-10
?
小怪獸愛吃肉

TA貢獻(xiàn)1852條經(jīng)驗(yàn) 獲得超1個(gè)贊

一個(gè)大大提高圖像質(zhì)量的選擇是轉(zhuǎn)換到一個(gè)不同的顏色空間,以便更容易地選擇您的顏色。特別是,HSV顏色空間定義像素顏色的色調(diào)(顏色)、飽和度(顏色的數(shù)量)和值(顏色的亮度)。

例如,可以使用以下函數(shù)將rgb圖像轉(zhuǎn)換為hsv空間。rgb2hsv,查找具有要定義為“非紅色”顏色的像素(例如,20到340度),將這些像素的飽和度設(shè)置為0(因此它們是灰度),然后使用該函數(shù)將圖像轉(zhuǎn)換回rgb空間。hsv2rgb:

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

下面是產(chǎn)生的圖像:

注意,與塞勒斯的溶液,你可以很容易地保持花上淡粉色的色調(diào)。還請(qǐng)注意,褐色色調(diào)的莖和地面也消失了。

關(guān)于根據(jù)圖像顏色屬性從圖像中選擇對(duì)象的一個(gè)很酷的示例,您可以查看SteveEddins的博客文章。兩個(gè)伙伴它描述了一種來自MathWorks的BrettShoelson的解決方案,用于從圖像中提取一個(gè)“朋友”。


關(guān)于選擇顏色范圍的注意事項(xiàng).。

另外一件可以幫助你選擇顏色范圍的事情是查看顏色的直方圖。hPlane)出現(xiàn)在HSV圖像的像素中。下面是一個(gè)使用函數(shù)的示例histc(或建議histcounts(如有的話)和bar:

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 label

下面是得到的像素顏色直方圖:

注意原始圖像是如何包含紅色、綠色和黃色像素的(有幾個(gè)橙色像素)。幾乎沒有青色、藍(lán)色、靛藍(lán)色或品紅色像素。還請(qǐng)注意,我在上面選擇的范圍(20到340度)很好地排除了大部分不是兩端兩個(gè)大的紅色星系團(tuán)的一部分的東西。


查看完整回答
反對(duì) 回復(fù) 2019-07-10
?
開滿天機(jī)

TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超13個(gè)贊

我真的不知道MATLAB是如何工作的,所以我不能對(duì)代碼進(jìn)行評(píng)論,但這可能有助于解釋RGB顏色是如何工作的。

當(dāng)使用RGB顏色時(shí),可以通過確保R、G和B的值都相同來確定灰度。因此,基本上您想要做的是檢測(cè)一個(gè)像素是否是紅色的,當(dāng)不只是使R、G和B相同時(shí)(您可以使用3的平均值來表示一個(gè)基本的結(jié)果)。

更難的部分是如何檢測(cè)一個(gè)像素是否實(shí)際上是紅色的,您不能僅僅檢查一個(gè)像素在R值中是否高,因?yàn)樗匀豢梢允橇硪环N顏色,而低的R值只意味著更深的紅色。

所以您可以這樣做:(我沒有MATLAB,所以假設(shè)語法):

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;
}

也許有更好的方法來檢測(cè)紅色和平均灰度,但這是一個(gè)開始;)


查看完整回答
反對(duì) 回復(fù) 2019-07-10
  • 3 回答
  • 0 關(guān)注
  • 983 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)