imagej / ImageJ

Public domain software for processing and analyzing scientific images
http://imagej.org
Other
556 stars 221 forks source link

Problem with rasterization of line and point ROIs #30

Open imagingbook opened 7 years ago

imagingbook commented 7 years ago

When I used the point iterator on line and point ROIs I found that the obtained point coordinates are often wrong. In particular,

Test images (containing selected ROIs) can be found here (tried to attach a ZIP file but it was rejected).

In this course I also looked at the behavious of Line.getPixels() and found similar deficiencies. The end point of the line was never included and the resulting array of pixel values also contained duplicates from the same locations (which I believe is not intended). However, even when interpolation is ON, the getPixels() method missed the last point on the line.

The mapping from float or double to int coordinates is apparently flawed in several places. I suggest to use this version to calculate the right offset (which will also work for negative coordinates):

double x, y;  // original position
int u = (int) Math.round(x - 0.5);
int v = (int) Math.round(y - 0.5);

Perhaps this should be packed into a single conversion method. There may be related problems in other places.

I have worked out a patch which can be found in this repo. Will send a pull request shortly. Hope this is useful, pls. let me know if anything's unclear.

--Wilhelm

PS: The announced pull request is here.

imagingbook commented 7 years ago

Posted a new pull request: https://github.com/imagej/imagej1/pull/34