Save the source data as tif

I need to analyze the part of the image selected as a submatrix in the tif file. I would like to have an image in raw format with no frills (scaling, axis, labels, etc.). How could I do this?

This is the code I'm using now:

 submatrix = im[x_min:x_max, y_min:y_max]
 plt.imshow(submatrix)
 plt.savefig("subplot_%03i_%03i.tif" % (index, peak_number), format = "tif")
+3
source share
1 answer

First, if you just want to keep the original values ​​or grayscale images of the raw values, the easiest way is to use PIL for this.

For example, this will create a 10x10 tif file in grayscale:

import numpy as np
import Image

data = np.random.randint(0, 255, (10,10)).astype(np.uint8)
im = Image.fromarray(data)
im.save('test.tif')

, matplotlib , , . Matplotlib ( ) dpi ( 80 100 ). , imshow , , - , .

matplotlib (, ), - :

import numpy as np
import matplotlib.pyplot as plt

dpi = 80 # Arbitrary. The number of pixels in the image will always be identical
data = np.random.random((10, 10))

height, width = np.array(data.shape, dtype=float) / dpi

fig = plt.figure(figsize=(width, height), dpi=dpi)
ax = fig.add_axes([0, 0, 1, 1])
ax.axis('off')

ax.imshow(data, interpolation='none')
fig.savefig('test.tif', dpi=dpi)
+2

All Articles