The_Learner
The_Learner

Reputation: 619

Removing a specific colored lines from a picture

In the image shown below, there a two colored lines (blue and black), I want to know the process of removing either blue or black colored lines. I am new to image processing, is there any process using Matlab or Python for detecting and removing specific colored lines.

enter image description here

Upvotes: 1

Views: 842

Answers (1)

MichaelTr7
MichaelTr7

Reputation: 4757

In MATLAB:

Not sure how much fidelity you need but this is a method of preserving only the blue uses rudimentary techniques including thresholding. Using a base blue colour defined in rgb-coordinates as rgb(0,0,255). By evaluating if a pixel does not have the colour content that is similar to our base blue colour. We can find the differences between each colour channel of our image and base blue colour then set the pixels to white if it does not fit the condition. White will be set by changing the pixel to rgb(255,255,255). In MATLAB layer 1 of the image is the red channel, layer 2 is the green channel and layer 3 is the blue channel. Below I use a set of for-loops to scan through the image. There are more concise ways of doing this but this way method seems to go through the fundamentals. RGB Layers

Removing Black Pixels

Blue Lines 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 = 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);

Removing Blue Pixels

Black Lines 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);

Ran using MATLAB R2019b

Upvotes: 3

Related Questions