This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Dim_Imsshow([reptile_arr[:,:,i] for i in range(3)], titles = ["red", "green", "blue"]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
reptile_ = cv2.imread("/content/sample_1.jpg") | |
blue, green, red = cv2.split(reptile_) | |
Dim_Imsshow([red, green, blue], titles = ["red", "green", "blue"]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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]]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |