store multiple images efficiently in Python data structure
<p>I have several images (their number might increase over time) and their corresponding annotated images - let's call them image masks.</p>

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

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

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

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

<p>PIL and Pillow are only marginally useful for this type of work. </p>

<p>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. </p>

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

python image algorithm opencv image-processing