What I am thinking of creating this time is a film that changes the color tone of the entire image, such as that attached to a camera. If you use the Numpy module, you can easily make 3 primary color films, but I wanted to increase the versatility and support all colors.
from PIL import Image
import numpy as np
def color_filter(img_source, rgb):
#Convert to a real array
img_source=np.array(img_source, dtype='float16')
#Film RGB is 0~255
if max(rgb)>255 or min(rgb)<0:
return Image.fromarray(np.unit8(img_source))
#Apply RGB film
img_source[:,:,0]*=rgb[0]/255
img_source[:,:,1]*=rgb[1]/255
img_source[:,:,2]*=rgb[2]/255
#Output after conversion to Image class
img_out=Image.fromarray(np.uint8(img_source))
return img_out
The RGB value of each pixel is multiplied by the ratio of the film's RGB to 255 (maximum RGB value). The color range can be changed from the original image to pitch black. The point is that the film when it is pitch black is a wall.
Film color: RGB (100,255,100) Film color: RGB (173,216, 230)
At first I thought that it would be possible to take the average with the filter value instead of the ratio, so I will also post the result. Since the wall could not be reproduced, it will be a failure.
from PIL import Image
import numpy as np
def color_filter2(img_source, rgb):
img_source=np.array(img_source, dtype="float16")
#Film RGB is 0~255
if max(rgb)>255 or min(rgb)<0:
return Image.fromarray(np.unit8(img_source))
#Apply RGB film
img_source[:,:,0]+=rgb[0]
img_source[:,:,0]/=2.0
img_source[:,:,1]+=rgb[1]
img_source[:,:,1]/=2.0
img_source[:,:,2]+=rgb[2]
img_source[:,:,2]/=2.0
#Output after conversion to Image class
return Image.fromarray(np.uint8(img_source))
Film color: RGB (100,255,100) Film color: RGB (173,216, 230) Wall: RGB (0,0,0) After all it is whitish overall.
I think there is demand for both, so please try various things. I hope you can use it to inflate image recognition data. (Addition) For some reason, I pasted the code when I forgot the slice notation ... The one I am currently pasting is lighter.
Recommended Posts