Basic Image processing functions
Basic image processing techniques
import numpy as np
from PIL import Image
import imageio
import skimage
import matplotlib.pyplot as plt
from skimage.transform import rotate,resize
read image from path
convert it to grayscale image
plot image
write image to a png file
path = 'https://upload.wikimedia.org/wikipedia/en/thumb/7/7d/Lenna_%28test_image%29.png/440px-Lenna_%28test_image%29.png'
plot histogram of gray scaled image
rotate image 60 degrees
resize images to 600x600 and show both images
How many coins are inside image? Use skimage's measure module :)
from skimage import measure
coins_path = 'https://media.imna.ir/d/2018/09/29/3/1530690.jpg'
np_image = imageio.imread(coins_path)
# your code
use deeplake module to download required files for the following tasks
! pip install deeplake
import deeplake
ds = deeplake.load("hub://activeloop/cifar100-test")
from typing import Callable
from datetime import datetime
from PIL import Image
import os
saving_address = "~/images_cifar100"
os.makedirs(saving_address , exist_ok=True)
def timeit(function:Callable):
first_time = datetime.now()
function()
last_time = datetime.now()
print(f"process took {(last_time - first_time).total_seconds()} seconds.")
return
def save_image(index):
image = ds.images[index].numpy()
Image.fromarray(image).save(f"{saving_address}/{index}.png")
import random
def save_loop():
# your code here!
return
timeit(save_loop)
import random
from multiprocessing import Pool
def save_multiprocessing():
# your code here!
return
timeit(save_multiprocessing)
import random
from multiprocessing.pool import ThreadPool
def save_multithreading():
# your code here!
return
timeit(save_multithreading)
import cv2
import random
def save_loop():
# your code here!
return
timeit(save_loop)
import random
from multiprocessing import Pool
def save_multiprocessing():
# your code here!
return
timeit(save_multiprocessing)
import random
from multiprocessing.pool import ThreadPool
def save_multithreading():
# your code here!
return
timeit(save_multithreading)
Where should we use multithreading? What about multiprocessing?