RMS
RMS

Reputation: 1430

store multiple images efficiently in Python data structure

I have several images (their number might increase over time) and their corresponding annotated images - let's call them image masks.

I want to convert the original images to Grayscale and the annotated masks to Binary images (B&W) and then save the gray scale values in a Pandas DataFrame/CSV file based on the B&W pixel coordinates.

So that means a lot of switching back and forth the original image and the binary images.

I don't want to read every time the images from file because it might be very time consuming.

Any suggestion which data structure should be used for storing several types of images in Python?

Upvotes: 0

Views: 910

Answers (2)

khushbu
khushbu

Reputation: 164

PIL and Pillow are only marginally useful for this type of work.

The basic algorithm used for "finding and counting" objects like you are trying to do goes something like this: 1. Conversion to grayscale 2. Thresholding (either automatically via Otsu method, or similar, or by manually setting the threshold values) 3. Contour detection 4. Masking and object counting based on your contours.

You can just use a Mat (of integers, Mat1i) would be Data structure fits in this scenario.

Upvotes: 1

RMS
RMS

Reputation: 1430

I used several lists and list.append() for storing the image.

For finding the white regions in the black & white images I used cv2.findNonZero().

Upvotes: 0

Related Questions