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

Image item with non linear axis normalization #3917

Open
vallsv opened this issue Jul 27, 2023 · 2 comments
Open

Image item with non linear axis normalization #3917

vallsv opened this issue Jul 27, 2023 · 2 comments

Comments

@vallsv
Copy link
Contributor

vallsv commented Jul 27, 2023

I have this request for Flint https://gitlab.esrf.fr/bliss/bliss/-/issues/3398

I could use a scatter but the rendering will probably not be very good.

Any idea if we could imagine such item in silx?

In the meantime i will probably try to create an item to see what i could do with the existing tools.

@vallsv
Copy link
Contributor Author

vallsv commented Jul 27, 2023

For the record, here is the implementation i will use.

from silx.gui.plot.items.scatter import Scatter

class ImageWithNormalization(Scatter):
    def __init__(self):
        Scatter.__init__(self)
        self.setVisualization(self.Visualization.IRREGULAR_GRID)

    def setData(self, image, xAxis, yAxis, copy=True):
        x = numpy.asarray(xAxis)
        y = numpy.asarray(yAxis)
        value = numpy.asarray(image)
        assert x.ndim == 1
        assert y.ndim == 1
        assert value.ndim == 2
        assert (y.shape[0], x.shape[0]) == value.shape

        ax = numpy.broadcast_to(x, value.shape)
        ay = numpy.broadcast_to(y.reshape(-1, 1), value.shape)
        Scatter.setData(self, ax.flatten(), ay.flatten(), value.flatten())

        self.setVisualizationParameter(
            self.VisualizationParameter.GRID_SHAPE,
            image.shape,
        )
        self.setVisualizationParameter(
            self.VisualizationParameter.GRID_BOUNDS,
            ((x[0], y[0]), (x[-1], y[-1])),
        )
        self.setVisualizationParameter(
            self.VisualizationParameter.GRID_MAJOR_ORDER, "row"
        )
image = numpy.array([[1, 2, 3, 4], [3, 4, 5, 6]])
xAxis = numpy.array([1, 2.5, 3, 3.5])
yAxis = numpy.array([3, 4])
item = ImageWithNormalization(image, xAxis, yAxis)

image

@t20100
Copy link
Member

t20100 commented Aug 30, 2024

Related to #4153

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants