2016-06-20 9 views
0

제목은 모든 것을 말합니다. 사진의 모든 빨간색 픽셀을 녹색 또는 파란색으로 변경하는 간단한 방법을 찾고 있습니다.단순한 jes 그림 색상을 빨간색에서 녹색 또는 파란색으로 전환하는 기능이 있습니까?

+3

: http://stackoverflow.com/questions/6483489/change-the-color-of-all-pixels-with-another-color – Srinath

+0

@Srinath : 허용 된 대답은 자이 썬에서 (NumPy를 사용하기 때문에) 작동하지 않을 수 있습니다. – mzjn

답변

0

각 픽셀에 대해 빨간색과 파란색 값을 바꿔야한다고 가정하면 다음과 같이 할 수 있습니다. 그렇지 않다면, 당신을 꽤 가깝게 여기에서 충분해야합니다.

데프 swapRedwithBlue (sourceImage) : 이미 여기 ansewred

width = getWidth(sourceImage) 
height = getHeight(sourceImage) 

for x in range(width): 
    for y in range(height): 

    sourcePixel = getPixel(sourceImage, x, y) 
    R = getRed(sourcePixel) 
    G = getGreen(sourcePixel) 
    B = getBlue(sourcePixel) 
    color = makeColor(B, G, R) 
    destinationPixel = getPixel(sourceImage, x, y) 
    setColor(destinationPixel, color) 

repaint(sourceImage)