Skip to content

Instantly share code, notes, and snippets.

View TuringNPcomplete's full-sized avatar
💭
Build, smile, and rebuild

Mustapha Unubi Momoh TuringNPcomplete

💭
Build, smile, and rebuild
View GitHub Profile
import cv2
eye_arr = np.array(eye_img)
blue, green, red = cv2.split(eye_arr)
show_images([red, green, blue], titles = ['red channel', 'green channel', 'blue channel'])
def one_channel(ims, nrows=1, ncols=None, titles= None, **kwargs):
"Show all images 'ims' as subplots with 'rows' using 'titles'."
if ncols is None: ncols = int(math.ceil(len(ims)/nrows))
if titles is None: titles = [None]*len(ims)
axs = subplots(nrows, ncols, **kwargs)[1].flat
for im,t,ax in zip(ims, titles, axs):
if im.ndim < 3:
show_image(im, ax = ax, title= t, cmap='gray')
else:
show_image(im, ax = ax, title= t)
!pip install -Uqq fastbook
import fastbook
fastbook.setup_book()
#importing all the packages and functions from fastai's vision
from fastai.vision import *
from fastbook import
#loading the color image
eye_img = Image.open("/content/eye.jpg")
#Importing all the required modules
!pip install -Uqq fastbook
import fastbook
fastbook.setup_book()
from fastai.vision import *
from fastbook import *
houses_df = pd.DataFrame({"House_No": ["1A", "2B", "3C"], "Median_Income": [145000, 50000, 10000]})
houses_df
Dim_Imsshow([reptile_arr[:,:,i] for i in range(3)], titles = ["red", "green", "blue"])
import cv2
reptile_ = cv2.imread("/content/sample_1.jpg")
blue, green, red = cv2.split(reptile_)
Dim_Imsshow([red, green, blue], titles = ["red", "green", "blue"])
#Cropping different parts of the reptile image
#Making row slices
show_images([reptile_arr[int(row_sz*start_mult): int(row_sz*(start_mult+0.2)), :] for start_mult in [0, 0.2, 0.4, 0.6, 0.8]])
#Making column slices
show_images([reptile_arr[:, int(row_sz*start_mult): int(row_sz*(start_mult+0.2))] for start_mult in [0, 0.2, 0.4, 0.6, 0.8]])
@TuringNPcomplete
TuringNPcomplete / InvokeTransFunction.py
Last active October 26, 2021 17:00
Using a custom defined function for converting color image to grayscale
grayscale_avr, grayscale_w, grayscale_lu = [transf_RBG(reptile_arr, RBG_conv_met) for RBG_conv_met in ["Average",
"Weighted_average", "Luminosity"] ]
Dim_Imsshow([grayscale_avr, grayscale_w, grayscale_lu], suptitle = "Grayscale Images based on: Average,
Weighted Average, and Luminosity methods", titles = ["Average", "Weighted Average", "Luminosity"])
@TuringNPcomplete
TuringNPcomplete / Img_transformer.py
Created October 25, 2021 23:01
A function that transforms color RGB image to the grayscale image using the three popular methods
def transf_RBG(image_arr, RBG_conv_met):
"""
Takes an image array and a conversion method as inputs
Transforms the color image to grayscale based on the specified method
"""
import cv2
blue, green, red = cv2.split(image_arr)
if RBG_conv_met == "Average":
grayscale_im = (np.round(3**-1*blue + 3**-1*green + 3**-1*red)).astype('uint8')
return grayscale_im
@TuringNPcomplete
TuringNPcomplete / Dim_Imsshow.py
Last active October 26, 2021 17:02
A modified version of fastai's show_images function that applies an appropriate colormap to 2D images
def Dim_Imsshow(ims, nrows=1, ncols=None, titles= None, **kwargs):
"Show all images 'ims' as subplots with 'rows' using 'titles'."
if ncols is None: ncols = int(math.ceil(len(ims)/nrows))
if titles is None: titles = [None]*len(ims)
axs = subplots(nrows, ncols, **kwargs)[1].flat
for im,t,ax in zip(ims, titles, axs):
if im.ndim < 3:
show_image(im, ax = ax, title= t, cmap='gray')
else:
show_image(im, ax = ax, title= t)