napari-plot-profile icon indicating copy to clipboard operation
napari-plot-profile copied to clipboard

Interpolation

Open haesleinhuepf opened this issue 4 years ago • 4 comments
trafficstars

It would be cool to have some interpolation for the measurements. It might also make sense to take the thickness of the annotated line into account and average over a small region. For that, we should figure out, how exactly this is done in other tools such as ImageJ

haesleinhuepf avatar Aug 22 '21 08:08 haesleinhuepf

I think the option of using a wider line (so a line that has pixels (just a few) in the transverse direction, relative to length) and then, for example, averaging the transverse pixels to get a value for that given length step is a good one. Could help with noisy images. However (and I sort of refer to that in #11 ) I think that if the user wants upscaling or smoothing or whatever, it's best to let the user apply filters whatnot to their image, get a new layer, and then use the tool to view that, rather than using the plot tool. Or, use the plot tool to get their data and then further process using other tools. Because manipulating the plot connected to the image without altering the image kind of abstracts and masks the processing being done.

psobolewskiPhD avatar Aug 26 '21 11:08 psobolewskiPhD

it's best to let the user apply filters whatnot to their image, get a new layer

That's a very interesting suggestion. I wished I had thought about that years ago in ImageJ.

Or, use the plot tool to get their data and then further process using other tools.

To be honest, exporting a line profile with nearest-neighbor rounding-artifacts cannot be fixed with post-processing. We really need to support interpolation.

haesleinhuepf avatar Aug 27 '21 06:08 haesleinhuepf

That's a very interesting suggestion. I wished I had thought about that years ago in ImageJ.

I only thought of it because this is what napari-pyclesperanto-assistant does so brilliantly!

Regarding interpolation I think we may have crossed streams here. I was thinking you were referring to the NumPlotPoints > LineLength, thus interpolating the in between the measured values, so to speak. Meanwhile, based on your previous post in the other issue, I think you're referring to cases where the overlay line lies on multiple pixels due to being at an angle.

So if we read out every pixel overlaid by the line, then I can see how touched may be more than the physical length of the line (euclidean length), so in this case we may actually need to reduce the final profile to the length of the line. In a sense it's doing a transformation from x-y to the vector , which may require some reshaping. I just hadn't thought of this as interpolation 😨 But of course it is.

At this point it may be useful to look at skimage.measure.profile_line() https://scikit-image.org/docs/dev/api/skimage.measure.html#skimage.measure.profile_line It does a lot of nice things:

  1. it has interpolation options, but note the length of the array returned is the ceiling of the line length, so it's interpolation to transform the values to fit the line length.
  2. it includes the option to use a wider line—as in your OP—with user option to reduce the transverse pixels to the line values, as well as interpolation options.

psobolewskiPhD avatar Aug 27 '21 07:08 psobolewskiPhD

At this point it may be useful to look at skimage.measure.profile_line()

Would like to take this task over? I have zero experience with that function but would love to see our custom implementation here replaced with something more sophisticated. :-)

haesleinhuepf avatar Aug 28 '21 14:08 haesleinhuepf