loading all images with different names from drive in python - python

Multiple images are stored in my google drive folder. All images have different names. I want to load them all for my deep learning project. All loaded images should be of type numpy array. What can I do?
Here is the code that I have implemented
import cv2
loc="" #My drive directory location
I have successfully loaded one images using
img=cv2.imread(str(loc)+"image_name.png",1)
I am stuck here, because names of all images are different

You can get all image names using os.listdir('you image folder path'). You can do something like this:
import os,cv2
for image_path in os.listdir('image folder path'):
cv2.imread(base_path + image_path,1)

Related

How open a stack of .tif images with python

i have a file with 300 .tif images, i want to open it with python and save them into an array, list or any similar structure. I´ve tried the code below but only appears 3 images. ¿Any solution?. Thanks.
raw = cv2.imread('sen_15Hz_500Hz_6_6A.tif')
print(np.shape(raw))
I´ve tried with PIL and cv2 too.
If you really have one single TIFF file with 300 images in it, the simplest is to open it with tifffile.
with TiffFile('temp.tif') as tif:
for page in tif.pages:
image = page.asarray()
If you want to use PIL look at the section "Image Sequences" here.

Loading WSI slide images to python and converting images to array

I have been new to WSI image processing and have been trying load images to python. I was successfull in loading slide images but it is not getting converted to an array for further processing. any help is appreciated. Following is the code i used
filenames = os.listdir("C:/Users/DELL/Downloads/dataset1")
X_train= np.array(filenames)
following is the output i get instead of an array of numbers representing an image
'TCGA-BA-4074-01A-01-BS1.9c51e4d0-cb30-412a-995a-97ac4f860a87.svs'
You should use specialized libraries for the reading of WSI image. Check these:
slideio
openslide
Keep in mind that normally the WSI slides are too large to load them
in the memory in the original resolution. You can load them partially or on the low resolutions. Both of the libraries support such a functionality.

Python :-extracting names of the images embedded inside a pdf

I have a pdf document containing several images. I want to retrieve the names of these images.
I know that ExtractImages extracts images from PDF. I feel that this will somewhere have the functionality to fetch the name of the image.
How to achieve this using python

Transferring training data from matlab to tensorflow

I have used MATLAB's Image Labeller App to create PixelLabelData for 500 images. So, I have got the original images and class labels for each image. This information is stored in a gTruth file which is in .mat format. I want to use this dataset for training a Unet in tensorflow (Google Colab).
I could not achieve the training task on MATLAb because of system limitations (insufficient RAM and no GPU).However, I have read that we can import training data from MATLAB for use in Colab. So, I uploaded original image set, the labelled pixels, and corresponding mat file (gTruth.mat) on Google Drive and then mounted the drive onto the Colab environment. But I don't know how to proceed forward with the mat file in Colab.
The pixelLabelTrainingData function will allow you to obtain two separate datastores for the input and pixel labeled images.
[imds,pxds] = pixelLabelTrainingData(gTruth);
https://www.mathworks.com/help/vision/ref/pixellabeltrainingdata.html
Given those, you can write each image, labeled image to parallel directories using the same naming convention using imwrite with the image file format of your choice.
inputImageDir = 'pathOfYourChoice';
count = 0;
while hasdata(imds)
img = read(imds);
fname = sprintf('img%d.png',count);
name = fullfile(inputImageDir,fname);
imwrite(img,name);
end
From there, you should be able to use standard tensorflow tooling (e.g. Dataset) to read in directories of images.

Loading Custom Dataset into TensorFlow CNN

We are using TensorFlow and python to create a custom CNN that will classify images into one of several categories. We have created our CNN based on this tutorial: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/tutorials/layers/cnn_mnist.py
Instead of reading in a pre-existing dataset like the MNIST dataset used in the tutorial, we would like to read in all images from multiple folders. The name of each folder is the label associated with all the images in that folder. Unfortunately we're very new to python and TensorFlow, could someone point us in the right direction, either with a tutorial or some basic code?
Thank you so much!
consider using the glob package. it allows you to import multiple files in subdirectories easily using patterns. https://docs.python.org/2/library/glob.html
import glob
import matplotlib.pyplot as plt
import numpy as np
images = glob.glob(<file pattern>)
img_list = [plt.imread(image) for image in images]
img_array = np.stack(tuple(img_list))
I haven't tested this so there might be errors but it should make a 3-d numpy array of images (each image a 2-d array). Is this the format you were looking for?

Categories