Skip to main content
New Participant
November 16, 2021
Question

save image to be used as array 8 bit

  • November 16, 2021
  • 2 replies
  • 431 views

Hi there,

I have to save 8 bit images with the following structure when converted to an array:

 

array([[[ 60, 124, 150, 255],
        [ 60, 124, 150, 255],
        [ 60, 124, 150, 255],
        ...,

 

But when I save as png 8 bit I obtain

 

array([[[115, 124,  67],
        [118, 127,  70],
        [122, 131,  76],
        ...,

 

Thank you!

This topic has been closed for replies.

2 replies

Brainiac
November 16, 2021

I have no idea how you are going from Photoshop to PNG to this array data, but that is not the form used by PNG. In particular, PNG-8 does not contain a 2D array of RGB or RGBA values, one per pixel; that would be impossible, since you have only 8 bits per pixel. Rather it stores a 2D array of indexes. Each index looks up an RGB value (not RGBA). A PNG-8 file may additionally include a tRNS chunk, which gives transparency values for specific index values.

New Participant
November 16, 2021

I used Python with PIL:

image_raw = np.array(Image.open('./image'))

 

Btw, it works with PNG-8 save for web.

 

Thank you!

New Participant
November 16, 2021

Obviously, they are 2 different examples. I would need the 255 at the end of each single array!