How to delete components of an image using python?

4

I am a beginner in python and would like to know how to remove components (red, blue or green) from an image using python, I downloaded some image processing libraries (like opencv). I would like to know if there is any function that does this in python or if it does not exist, could you inform me what the process would be to do this? Knowing the process I can create the algorithm in the "hand".
OBS: if possible, avoid responses based only on external links, that is, do not leave as a response only the link to an external page.
OBS2: I have nothing "ready", I'm just reading the image using opencv.

import cv2
imagem = cv2.imread("../Imagens/im01.jpg");
    
asked by anonymous 03.12.2017 / 13:56

1 answer

1

You can 'zero' color channels independently as follows:

# Removendo canal AZUL
img[:,:,0] = 0  

# Removendo canal VERDE
img[:,:,1] = 0  

# Removendo canal VERMELHO
img[:,:,2] = 0  

Here is an example code that can remove specific channels from a given image:

import cv2
import copy

# Abre image original
img = cv2.imread("original.png")

# Remove canal AZUL
img_no_blue = copy.copy(img)
img_no_blue[:,:,0] = 0

# Remove canal VERDE
img_no_green = copy.copy(img)
img_no_green[:,:,1] = 0

# Remove canal VERMELHO
img_no_red = copy.copy(img)
img_no_red[:,:,2] = 0

# Exibe as imagens
cv2.imshow('Imagem Original', img )
cv2.imshow('Azul Removido', img_no_blue )
cv2.imshow('Verde Removido', img_no_green )
cv2.imshow('Vermelho Removido', img_no_red )

cv2.waitKey(0)
cv2.destroyAllWindows()

Original Image:

RemovedChannels:

    
05.12.2017 / 14:56