1

I have instructions for a file format which contains .png images as

Each parquet file contains tens of thousands of 137x236 grayscale images.Each row in the parquet files contains an image_id column, and the flattened image

I've opened these using python and can visualise using matplotlib's imshow. Can anyone suggest me any method to save these in a directory as .png using python?

I can not download any other dependencies and packages

I have used

ima = pandas.read_parquet(path_of_file)
ima.shape
>>(50210, 32333)

ima.head(2)
>>
   image_id      0     1    ...  32330  32331

0  Train_50210  246    253  ...    251    250   
1  Train_50211  250    245  ...    241    244   

Deshwal
  • 3,436
  • 4
  • 35
  • 94

1 Answers1

0

For a non-flattened data something like this could work:

import pyarrow.parquet as pq

index = 0
table = pq.read_table('data.parquet')
for img in table['image']:
    b = img['bytes'].as_py()
    with open(f'{index}.png', 'wb') as f:
        f.write(b)
        index+=1

as_py() returns array of bytes

In your case you will have to collect the array manually from flattened data, iterating through each column and then dumping it straight into a png file using write() in binary mode 'wb'