Jean-Pat
Jean-Pat

Reputation: 1871

How to plot images of different size at the same resolution?

A collection of images are plotted as follow:

figure(num=None, figsize=(16, 14), dpi=300)
k=1
for i in range(1,10):
    for j in range(1,6):
        subplot(9,5,k,xticks=[],yticks=[])
        imshow(rgb_chromosomes[k-1],interpolation='nearest')
        k=k+1

It is visible that from a image to an other, pixels are not the same size. How to fix that issue?

collection of images

Upvotes: 1

Views: 572

Answers (2)

tacaswell
tacaswell

Reputation: 87596

so, from image to image are the pixels different sizes? From context, I am guessing that these are all snippets from the same image/imaging conditions and you want the scale to be the same in all of them.

Something like:

fig, ax_lst = plt.subplots(9, 6)  # better way to set up your axes
for k, ax in enumerate(ax_lst.ravel()):
    ax.imshow(rgb_chromosomes[k], interpolation='none')
    ax.set_xlim([0, max_image_width])
    ax.set_ylim([0, max_image_height])
    ax.set_frame_on(False)

Upvotes: 0

user1196549
user1196549

Reputation:

Use interpolation= 'bilinear' and subsample the result with regular spacing (say take every other four pixel, this depends on the final pixel size you want) and form a tiny image. Then magnify this tiny image with 'nearest' interpolation.

You can also keep the 'nearest' setting for the first interpolation, but the result will look ugly.

Upvotes: 1

Related Questions