How to delete components from an image using python?

Asked

Viewed 1,631 times

3

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

import cv2
imagem = cv2.imread("../Imagens/im01.jpg");
  • @Andersoncarloswoss, it’s not the same question, it’s a new question. I was with 2 doubts about image manipulation, as putting the 2 in a question could only cause problems, I posted each one separate from the other

  • My mistake. I’m sorry.

  • Mate, what do you mean by "eliminate"? Would it remove the channel from a certain color, keeping only the other channels? Suppose yes, take a look at this link (or look for "python opencv RGB split" in Google): http://knowpapa.com/opencv-rgb-split/ Like me I commented on your other question, not that the subject is not valid, but I think you should try something first because it will help you in your learning. :)

  • @Luizvieira hello again Luiz. Man, the worst thing I’ve ever researched before on the subject, but my problem is that most of the time I don’t know how to elaborate the research. I initially put "eliminate Components of image using python", but this did not return me good results. I will look at your link and use your search suggestion. Again, thank you for responding and helping me.

  • Oops, for nothing. Yeah, that’s really the difficulty. : ) Be especially careful with the word "component", because in image processing it almost always means something like "a characteristic part of an element of interest that you look for in the image", as the curved edges of a coin in a coin photo, draw?

  • And if you are studying image processing, I suggest getting a good source of study (a book like the "Image Processing and Acquisition using Python") to at least understand the basic terms and tals.

Show 1 more comment

1 answer

1


You can 'reset' the 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 of code capable of removing 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:

inserir a descrição da imagem aqui

Removed Channels:

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.