Posted by
Michael Schmid on
Oct 22, 2013; 4:11pm
URL: http://imagej.273.s1.nabble.com/Python-iteration-through-Pixel-ROI-to-slow-tp5005274p5005269.html
Hi Andreas,
unfortunately I don't understand what your plugin should do, but anyhow:
The rt.getValue command is nothing that I'd put into an in the inner loop; it needs to lookup the column index from the String. It would be much faster using an array than the ResultsTable; write your data to the ResultsTable at the very end.
One more point: If the rois are much smaller than the image size, it would be much faster stepping through the rois in the outer loop, and using the bounding rectangle (getBounds()) of each roi for the x and y coordinates, so the inner loop would be just over the pixels within the bounding rectangle. You may need some additional arrays to store intermediate results.
---
Concerning roi.getMask(): First note that it is null for rectangular Rois; you will get an exception if you have a rectangular roi and don't check for this. Also, the mask is only for pixels within the getBounds() rectangle. So it contains getBounds().width * getBounds().height pixels.
If you can explain what your macro should do, maybe there is some trick to make it faster...
Michael
________________________________________________________________
On Oct 22, 2013, at 14:06, Andreas Rzepecki wrote:
> Hello together,
>
> I wrote a more or less complex plugin in python for Fiji, which helps me to analyse every pixel of an image (row by row) in combination with some ROI calculation. The iteration I use is:
>
> for j in range(x):
> IJ.showProgress(j, x)
> sumpix_sap = 0
> for i in range(y):
> sap_row = 0
> for roi in RoiManager.getInstance().getRoisAsArray():
> if roi.contains(j, i):
> pix_sap = rt.getValue("Sapflow per Pixel", sap_row)
> sumpix_sap = sumpix_sap + pix_sap
> break
> else:
> sap_row = sap_row + 1
> table.incrementCounter()
> table.addValue("Sapflow sum", sumpix_sap * 1000000)
> IJ.showProgress(1)
>
>
> For a test picture (620x90 pixel, 197 ROIs) it needs some seconds to calculate my result values.
>
> For another test picture (592x301, 1172 ROIs) it needs around 6 minutes.
>
> Unfortunatly I need to analyse pictures with 6000x1000+ pixel and 100000+ ROIs. I tried it but stopped it after around 30 minutes with the progress bar not moving once.
>
> Is this a problem with python iterations or did I something wrong with my code, which slows down the progress unnecessarily?
>
> I would appreciate any hint/help. Thank you very much in advance.
>
> Andreas
>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html