silx-kit / silx

silx toolkit
http://www.silx.org/doc/silx/latest/
MIT License
128 stars 73 forks source link

circular profile tool #3610

Closed kklmn closed 2 years ago

kklmn commented 2 years ago

Dear silx creators,

I need a profile tool that integrates a 2D image along a circular arc. I imagine 3 handles visible on the image plot that define the arc and a SpinBox that sets the width. Can you please advise on where to start (to find good parent classes) about the following aspects:

Thank you very much in advance!

vallsv commented 2 years ago

I think there is 2 ways for you to implement such think, depending on what you want to do.

1) You can create your own ROI profile, if you want to integrate that in the silx profile tools

See for example, examples/plotProfile.py, but there is not much things inside.

You can take a look at:

This provides a lot of flexibility, but but have to work with the silx "profile" API.

2) If you need more freedom, or you want to handle it on your own:

You can take a look at examples/plotInteractiveImageROI.py

kklmn commented 2 years ago

Thanks @vallsv! This is a good start.

kklmn commented 2 years ago

Hi @vallsv,

By now I've figured out how to use ArcROI in my tools.

I notice that at large radii the arc gets segmented as shown here: image Here I've quite strongly zoomed horizontally. My images have lines that are also very weakly curved, so large radii will be very usual for me. Can the roi shape be plotted smoother? Where this can be controlled?

vallsv commented 2 years ago

Could you send to us the parameters of your ROI? It's kind of weird, i can't figure out how it could render such shape.

Basically, there is a polygonization done inside the ROI. Looking at the code it looks to be fixed by a point every 0.1deg.

https://github.com/silx-kit/silx/blob/master/src/silx/gui/plot/items/_arc_roi.py#L638

At this stage it's difficult to compute something depending on the actual plot zoom, and for now we dont have real circle/arc primitives, so we have to find a compromise as a nice fixed value.

The actual state is kind of bad, but we can improve it with a minimum fixed number of points, for example 100

# delta = 0.1 if geometry.endAngle >= geometry.startAngle else -0.1
sign = numpy.sign(geometry.endAngle - geometry.startAngle)
delta = min(0.1, abs((geometry.startAngle - geometry.endAngle) / 100) * sign

Maybe other parameters like the radius could be used to get a better result, i can't tell. You have maybe a better idea?

What do you think @t20100?

kklmn commented 2 years ago

I start from the example plotInteractiveImageROI.py. Instead of RectangleROI I use:

plot.setKeepDataAspectRatio(False)
roi = ArcROI()
roi.setGeometry(center=(-3570, 505), innerRadius=3900, outerRadius=3915,
                startAngle=-0.13, endAngle=0.13)

Then zoom the roi, but already on the big picture the segmentation is visible.

kklmn commented 2 years ago

Yes, probably to give a reasonable number of points, like 100, would be a good solution.

vallsv commented 2 years ago

Here is with my patch

image

I think the patch is good enough to be integrated as it is, ill just double check with my colleagues first.

t20100 commented 2 years ago

@vallsv , it sounds good to me

kklmn commented 2 years ago

Thanks again!