빨간색이있는 경우 픽셀 단위로 확인하면서 이미지를 가져 오려고합니다.이미지 조작, openCV 및 numpy 사용. 빨간색이 아닌 이미지를 반환하려고 시도합니다.
흰색으로 교체하십시오. 모든 픽셀을 통과하면 빨간색 대신 흰색으로 새 이미지가 반환됩니다. ,
import cv2
import numpy as np
def take_out_red():
'''
Takes an image, and returns the same image with red replaced
by white
------------------------------------------------------------
Postconditions:
returns
new_img (no red)
'''
img = cv2.imread('red.png',1)
#Reads the image#
new_img = img
#Makes a copy of the image
for i in range(499):
for y in range(499):
if np.all(img[i,y]) == np.all([0,0,253]):
#[0,0,253] is a red pixel
#Supposed to check if the particular pixel is red
new_img[i,y] == [255,255,255]
#if it is red, it'll replace that pixel in the new_image
#with a white pixel
return cv2.imshow('image',new_img)
#returns the new_image with no red
어떤 도움은 매우 극명하게 될 것이다 사전에 너무 감사합니다 :
다음
내 시도이다.
어떻게 빨간색을 정의합니까? 당신은 단지 BGR 색 공간, 구글 "hsv"에서 빨간 채널을 대체 할 수 없으며 H 채널을 수정 한 다음 다시 변환 할 수 없습니다. – Silencer