Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Issue with MR 2D1D transform binding #44

Open
sfarrens opened this issue Jan 18, 2023 · 0 comments
Open

[BUG] Issue with MR 2D1D transform binding #44

sfarrens opened this issue Jan 18, 2023 · 0 comments
Labels

Comments

@sfarrens
Copy link
Member

The Python binding for the MR 2D1D transform gives different results to the executable binary. This needs to be investigated and fixed.

Example

See the following example when running PySAP.

import os
import numpy as np
import matplotlib.pyplot as plt

import pysap
from pysap.data import get_sample_data
from pysap.extensions import mr2d1d_trans
from pysap.extensions.sparse2d import MR2D1D

# Example MR data
mr_image = get_sample_data(dataset_name="multiresolution").data

# Transform settings
type_of_transform=14
normalize=True
number_of_scales_2D=5
number_of_scales_1D=4

# Python Binding for MR 2D1D
MR2D1D_inst = MR2D1D(
    type_of_transform=type_of_transform, 
    normalize=normalize, 
    NbrScale2d=number_of_scales_2D, 
    Nbr_Plan=number_of_scales_1D,
)
MR2D1D_inst.transform(mr_image)
MR2D1D_res = MR2D1D_inst.cube

# Python Wrapper for MR 2D1D
with pysap.TempDir(isap=True) as tmpdir:
    in_image = os.path.join(tmpdir, "in.fits")
    out_file = os.path.join(tmpdir, "out.mr")
    pysap.io.save(mr_image, in_image)
    
    mr2d1d_trans(
        in_image, 
        out_file, 
        type_of_multiresolution_transform=type_of_transform, 
        normalize=normalize, 
        number_of_scales_2D=number_of_scales_2D,
        number_of_scales_1D=number_of_scales_1D,
    )
    
    mr2d1d_trans_res = np.copy(pysap.io.load(out_file))

The input data look like this

fig, axes = plt.subplots(nrows=1, ncols=4, figsize=(12, 5))

for index, (ax, image) in enumerate(zip(axes, mr_image.T)):
    ax.imshow(image)
    ax.axis('off')
    ax.set_title(f'Scale {index + 1}')
    
fig.suptitle('Multiresolution Data', fontsize=20)

plt.show()

image

and the transform results look like this.

fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(12, 5))

ax[0].plot(MR2D1D_res, label='Binding')
ax[0].plot(mr2d1d_trans_res, label='Wrapper')
ax[0].legend()
ax[0].set_title('MR 2D1D Transform')

ax[1].plot(MR2D1D_res - mr2d1d_trans_res)
ax[1].set_title('Binding - Wrapper')

plt.show()

image

@sfarrens sfarrens added the bug label Jan 18, 2023
@sfarrens sfarrens changed the title Issue with MR 2D1D transform binding [BUG] Issue with MR 2D1D transform binding Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant