Unable to interpolate when upsizing image Python

from ij import IJ, ImagePlus

scale = 4

IJ.run('Blobs (25K)')
imp = IJ.getImage() #selects the top image and names it imp
imp.show()
x = imp.getWidth()
y = imp.getHeight()

ip = imp.getProcessor().resize (x * scale, y * scale, 'bicubic')
imp.setProcessor(ip)

I am trying to upsize an image by specific factors. When I run the resize() function with the x and y arguments only the script upsizes but it does not interpolate the image. I need to be able to upsize with interpolation but when I try to add the third argument the code throws a
“TypeError: resize(): 3rd arg can’t be coerced to boolean”

What is the correct way to enter the third argument to get the resize command to upscale with interpolation?

Hi @photojoe ,

Welcome to the forum!

Short answer:

ip = imp.getProcessor().resize (x * scale, y * scale, True)

should resize your image with bilinear interpolation.

More details:
From the ImageProcessor api, the resize method takes a boolean as its third argument (like the error says). Passing true will bilinearly interpolate. Cubic interpolation is not built directly into the ImageProcessor class.

Write back if you still have questions
John

John,

Thanks for your reply. I appreciate your help. I tried entering “True” as the third argument, and while the code runs, it does not interpolate. I get an image with 4x4 blocks of pixels that are the same value.

I thought I could use interpolation based on the description here: Scaler (ImageJ API)

Joe

1 Like

Hey Joe,

Using Scaler is a good idea, glad you found it. Consider posting back a code snippet if you get it to work and mark your own reply as a solution.

John