Skip to content Skip to sidebar Skip to footer

Same Data Saved Generate Different Images - Python

I have in my code two methods to save images data, one to just save it values in greyscale and another one to generate a heat map image: def save_image(self, name): ''' Sav

Solution 1:

Apparently the data are in row-major format, but you're iterating as if it were in column-major format, which rotates the whole thing by -90 degrees.

The quick fix is to replace this line:

color = self.data[x][y]

… with this one:

color = self.data[y][x]

(Although presumably data is an array, so you really ought to be using self.data[y, x] instead.)

A clearer fix is:

for row inrange(self.height):
    for col inrange(self.width):
        color = self.data[row][col]
        color = int(Utils.translate_range(color, self.range_min, self.range_max, 0, 255))
        putpixel((col, row), (color, color, color))

This may not be entirely clear from the pyplot documentation, but if you look at imshow, it explains that it takes an array-like object of shape (n, m) and displays it as an MxN image.

Post a Comment for "Same Data Saved Generate Different Images - Python"