import cv2
import numpy as np import scipy import matplotlib.pyplot as plot from PIL import Image from skimage import io import glob from skimage import io, img_as_float
img = cv2.imread(r"C:\Users\hoday\Desktop\GRAPE_IMG\GrapeBox.jpg", 1) img = np.float32(img)
blue_img, green_img, red_img = cv2.split(img) #split the image into 3 channels - BGR
channels = [blue_img, green_img, red_img] std_channels = []
for channel in channels:
lst = []
img_row = (channel.shape)[0]
img_col = (channel.shape)[1]
for row in range(1, img_row-1): #for 5X5 1--->2
for col in range(1, img_col-1): #for 5X5 1--->2
mask = channel[row-1:row+2, col-1:col+2] #for 5X5 ---> mask = channel[row-2:row+3, col-2:col+3]
lst.append(mask.std())
std_channel = np.array(lst)
std_channel = std_channel.reshape(img_row-2, img_col-2) #for 5X5 2--->4
std_channels.append(std_channel)
img_merged = cv2.merge(std_channels) cv2.imwrite(r"C:\Users\hoday\Desktop\GRAPE_IMG\normalStd.png", img_merged)
Hi, I'm trying to go through the pixels of an image and take out a new image consisting of std Just like what was done in the next video :
https://www.youtube.com/watch?v=ZoaEDbivmOE&t=80s
I split the image into 3 channels and tried to update a new array for each channel but when I try to run the code I get stuck. For example Instead of print the value 5.58 for img[0:3, 0:3].std() like it is supposed to do, the value that it's print is 1.28 - now that is the value of std for one channel but i want the merge one with all the three ...
Probably i dont merge the channels in the right way but i have no idea how else i can do it.