0

I have a binary black and white image as a .tif file. I do this

image = imageio.imread(path)
print ' Min and max ', image.min(), image.max(), image.shape, type(image[0,0])
imageio.imsave(path, image)

Which prints

Min and max  0 255 (1024, 1024) <type 'numpy.uint8'>

However, after I run that, black and white colors have reversed. What is going on?

When I try this command

identify -verbose 6hr-001-DIC.tif

on the pre-processed image, I see

tiff:photometric: min-is-white

But after I run the python code, it shows tiff:photometric: min-is-black

So how can I address this, i.e. make sure it's not getting changed?

Baron Yugovich
  • 3,843
  • 12
  • 48
  • 76

1 Answers1

3

As @Mark Stechell pointed you need to use the photometric metadata field. First make sure you have installed tifffile. For the sake of demonstration I am using the marbles image in grayscale. Now the code:

import imageio

image = imageio.imread('gmarbles.tif')
print(' Min and max ', image.min(), image.max(), image.shape, type(image[0, 0]))

image.meta['photometric'] = 'miniswhite'
imageio.imsave('white.tif', image)

white image

or alternative set to 'minisblack':

black image

Dani Mesejo
  • 61,499
  • 6
  • 49
  • 76