【问题标题】:Removing a specific colored lines from a picture从图片中删除特定的彩色线条
【发布时间】:2023-03-17 07:19:01
【问题描述】:

在下图中,有两条彩色线条(蓝色和黑色),我想知道去除蓝色或黑色线条的过程。我是图像处理的新手,是否有任何使用 Matlab 或 Python 来检测和删除特定彩色线条的过程。

【问题讨论】:

  • 你可以查看openCV for python。
  • 我可以秒 OpenCV 它运行得非常快。它也可以使用导入名称cv2。在OpenCV 中使用 BGR(蓝、绿、红)排序也很常见。

标签: python matlab matplotlib image-processing


【解决方案1】:

在 MATLAB 中:

不确定您需要多少保真度,但这是一种仅保留蓝色的方法,使用包括阈值处理在内的基本技术。使用rgb-coordinates 中定义的基本蓝色作为rgb(0,0,255)。通过评估像素是否不具有与我们的基础蓝色相似的颜色内容。我们可以找到图像的每个颜色通道与基础蓝色之间的差异,如果不符合条件,则将像素设置为白色。白色将通过将像素更改为rgb(255,255,255) 来设置。在 MATLAB 中,图像的第 1 层是红色通道,第 2 层是绿色通道,第 3 层是蓝色通道。下面我使用一组 for 循环来扫描图像。有更简洁的方法可以做到这一点,但这种方法似乎贯穿了基础。

去除黑色像素

%Reading in the image%
Image = imread("Image.png");
[Image_Height,Image_Width,Number_Of_Colour_Channels] = size(Image);
subplot(1,2,1); imshow(Image);

%Defining a blue pixel base%
Red_Content = 0;
Green_Content = 0;
Blue_Content = 255;

Red_Channel = 1;
Green_Channel = 2;
Blue_Channel = 3;

Red_Threshold = 100;
Green_Threshold = 100;
Blue_Threshold = 230;

for Row_Scanner = 1: Image_Height
   for Column_Scanner = 1: Image_Width 
    
    Red_Value = Image(Row_Scanner,Column_Scanner,Red_Channel);
    Green_Value = Image(Row_Scanner,Column_Scanner,Green_Channel);
    Blue_Value = Image(Row_Scanner,Column_Scanner,Blue_Channel);
    
    if(Blue_Value < Blue_Threshold || Green_Value > Green_Threshold || Red_Value > Red_Threshold)
        Image(Row_Scanner,Column_Scanner,1) = 255; 
        Image(Row_Scanner,Column_Scanner,2) = 255; 
        Image(Row_Scanner,Column_Scanner,3) = 255; 
    end    
   end
end

subplot(1,2,2); imshow(Image);

去除蓝色像素

%Reading in the image%
Image = imread("Image.png");
[Image_Height,Image_Width,Number_Of_Colour_Channels] = size(Image);
subplot(1,2,1); imshow(Image);

%Defining a blue pixel base%
Red_Content = 0;
Green_Content = 0;
Blue_Content = 255;

Red_Channel = 1;
Green_Channel = 2;
Blue_Channel = 3;

Red_Threshold = 240;
Green_Threshold = 240;
Blue_Threshold = 100;

for Row_Scanner = 1: Image_Height
   for Column_Scanner = 1: Image_Width 
    
    Red_Value = Image(Row_Scanner,Column_Scanner,Red_Channel);
    Green_Value = Image(Row_Scanner,Column_Scanner,Green_Channel);
    Blue_Value = Image(Row_Scanner,Column_Scanner,Blue_Channel);
    
    if(~(Blue_Value < Blue_Threshold || Green_Value > Green_Threshold || Red_Value > Red_Threshold))
        Image(Row_Scanner,Column_Scanner,1) = 255; 
        Image(Row_Scanner,Column_Scanner,2) = 255; 
        Image(Row_Scanner,Column_Scanner,3) = 255; 
    end      
   end
end

subplot(1,2,2); imshow(Image);

使用 MATLAB R2019b 运行

【讨论】:

  • 非常感谢,非常感谢您的帮助
  • 没问题,乐于助人! :)
猜你喜欢
  • 1970-01-01
  • 2017-11-27
  • 1970-01-01
  • 2011-07-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-08
  • 2018-01-16
相关资源
最近更新 更多