This function is where we use our undercomplete autoencoder. #Read all grayscale images and append into numpy list Img = cv2.imread("color_images/color_" str(i) ".jpg" ) #Read all color images and append into numpy list We import all the training and testing datasets which will be used by the autoencoder. filenames = gl.glob("flower_images\*.png")Ĭv2.imwrite('actual_gray_test/gray_' str(count) '.jpg', img) Write the converted images into a new folder. Iterate through each image and convert into grayscale while also resizing each image to 128* 128 pixels. Read all the flowers from the specified folder and store it in a variable. Here we prepare the dataset which will be used later for testing the model. Gray_img = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) Finally, the RGB and grayscale images are renamed and written in their respective new folders. Convert each image to grayscale using cv2.cvtColor() function from the OpenCV library. Path_tulips = 'flower_photos/tulips/*.jpg' Path_sunflowers = 'flower_photos/sunflowers/*.jpg' Path_dandelion = 'flower_photos/dandelion/*.jpg' These will be used for training purposes. import tensorflow as tfĭefine path variables for the different flowers. Import all the libraries that we will need, namely tensorflow, cv2, glob, numpy and matplotlib. At this point, we have Y in F(X)=Y and try to generate the input X for which we will get the output. Our encoder part is a function F such that F(X) = Y.ĭecoder part of autoencoder will try to reverse process by generating the actual grayscale images from the features. For example, X is the grayscale image and Y is the feature of adding colors. The basic idea of using Autoencoders for generating grayscale images is as follows:Įncoder part of autoencoder will learn the features of colored images by analyzing the actual dataset.
0 Comments
Leave a Reply. |