Python Forum

Full Version: Attribute Error - trying to create a pixel array out of PNG files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Have 40 PNG files, ground truth labels for 40 DICOM images, that I am attempting to convert into an array for input into a Fully Convolutional Neural Network.

Linked the files to a Google Colab notebook from my Google Drive and globbed them together via the masks variable that has a length of 40 via the print(len(masks)) call. However, when I attempt to read each individual PNG file and append its pixel data to the pixel_data1 array, I receive the "AttributeError" below.

The PNG files are of different sizes (256 x 256, 288 x 288, and 320 x 320), as was the case with the 40 DICOM files that I have created the pixel array from in a similar code block as below.

Tried to also use cv2.imread() for dataset1 but also have had no success in running the for loop successfully.

pixel_data1 = []
masks = glob.glob("/content/drive/My Drive/Masks/IMG*.png");
for mask in masks:
    dataset1 = imageio.imread(mask)
    pixel_data1.append(dataset1.pixel_array)
print(len(masks))
print(pixel_data1)
Outputs the following error: "AttributeError: 'Array' object has no attribute 'pixel_array'"
imageio documentation says imread returns a numpy array. I don't see where numpy arrays have a pixel_data attribute.