Closed davidenitti closed 4 years ago
Hi Davide,
Yes, astroalign returns by default a float64
(double) image, regardless of the input type. Internally I have to promote it to float to do the interpolation.
I'm gonna test this and think what's the best course of action. In the meantime, let me ask you, in your case is it both source
and target
of type uint8
? Or just one of them?
What kind of artifacts does it create? What is the range of the output image?
~Yes, astroalign returns by default a
float64
(double) image, regardless of the input type. Internally I have to promote it to float to do the interpolation.~
Actually, this is not true. I will have to investigate, I never really had to work with uint8
images.
I checked the code, I think the problem is the parameter clip=False when "warp" is called (inside apply_transform):
aligned_image = warp(
source_data,
inverse_map=transform.inverse,
output_shape=target_data.shape,
order=3,
mode="constant",
cval=_np.median(source_data),
clip=False,
preserve_range=True,
)
as you can read in the skimage.transform.warp documentation:
clip bool, optional Whether to clip the output to the range of values of the input image. This is enabled by default, since higher order interpolation may produce values outside the given input range.
Indeed it might be better to work in float, but the problem is present in float as well. if the range is 0-1 I expect the output to be between 0 and 1, if it's between 0-255 I would expect the output to be in that range. This is not the case for that parameter. I would set clip=True, unless you chose clip=False for some reason I don't know
Good catch. Yes, it should be clip=True
. I'll fix that in the next release. It's issue #51 now.
Version 2.1
implements clip=True
now.
Given an image uint8, apply_transform will return an image that is not in the range 0-255. This creates artifacts. The only way to solve the problem is to save result in float, clamp between 0 and 255 and then reconvert to uint8