Edit photo - Change color effects - Image filtering in Python
Code:-
from skimage import data, io
import random
try:
rgb_image = data.imread("Collage.jpg")
#print(rgb_image.shape)
red_image = rgb_image.copy()
green_image = rgb_image.copy()
blue_image = rgb_image.copy()
red_image[:, :, (1, 2)] = 0
io.imsave("red_output_image.jpg", red_image)
green_image[:, :, (0, 2)] = 0
io.imsave("green_output_image.jpg", green_image)
blue_image[:, :, (0, 1)] = 0
io.imsave("blue_output_image.jpg", blue_image)
rgb_image[0:1328, 0:1328, random.randint(0,2)] = random.randint(11, 100)
rgb_image[0:1328, 1329:2659, random.randint(0,2)] = random.randint(11, 100)
rgb_image[0:1328, 2660:3987, random.randint(0,2)] = random.randint(11, 100)
rgb_image[1329:2659, 0:1328, random.randint(0,2)] = random.randint(11, 100)
rgb_image[1329:2659, 1329:2659, random.randint(0,2)] = random.randint(11, 100)
rgb_image[1329:2659, 2660:3987, random.randint(0,2)] = random.randint(11, 100)
rgb_image[2660:3987, 0:1328, random.randint(0,2)] = random.randint(11, 100)
rgb_image[2660:3987, 1329:2659, random.randint(0,2)] = random.randint(11, 100)
rgb_image[2660:3987, 2660:3987, random.randint(0,2)] = random.randint(11, 100)
io.imsave("output_image.jpg", rgb_image)
except Exception as e:
print(e)
Output:-
Original photo:
Red Image:
Green Image:
Blue Image:
Random output image 1:
Random output image 2:
from skimage import data, io
import random
try:
rgb_image = data.imread("Collage.jpg")
#print(rgb_image.shape)
red_image = rgb_image.copy()
green_image = rgb_image.copy()
blue_image = rgb_image.copy()
red_image[:, :, (1, 2)] = 0
io.imsave("red_output_image.jpg", red_image)
green_image[:, :, (0, 2)] = 0
io.imsave("green_output_image.jpg", green_image)
blue_image[:, :, (0, 1)] = 0
io.imsave("blue_output_image.jpg", blue_image)
rgb_image[0:1328, 0:1328, random.randint(0,2)] = random.randint(11, 100)
rgb_image[0:1328, 1329:2659, random.randint(0,2)] = random.randint(11, 100)
rgb_image[0:1328, 2660:3987, random.randint(0,2)] = random.randint(11, 100)
rgb_image[1329:2659, 0:1328, random.randint(0,2)] = random.randint(11, 100)
rgb_image[1329:2659, 1329:2659, random.randint(0,2)] = random.randint(11, 100)
rgb_image[1329:2659, 2660:3987, random.randint(0,2)] = random.randint(11, 100)
rgb_image[2660:3987, 0:1328, random.randint(0,2)] = random.randint(11, 100)
rgb_image[2660:3987, 1329:2659, random.randint(0,2)] = random.randint(11, 100)
rgb_image[2660:3987, 2660:3987, random.randint(0,2)] = random.randint(11, 100)
io.imsave("output_image.jpg", rgb_image)
except Exception as e:
print(e)
Output:-
Original photo:
Red Image:
Green Image:
Blue Image:
Random output image 1:
Random output image 2:
This example manipulates an image by separating and zeroing color channels with scikit-image, producing red, green, and blue tinted versions. Because images are just NumPy arrays here, channel operations are simple slicing.
Understanding how the red, green, and blue planes combine is the foundation for color filtering, channel swaps, and many other effects.






Comments
Post a Comment