ROI Extract Javascript Rewrite

javascript
roi
Tags: #<Tag:0x00007fd542c7f938> #<Tag:0x00007fd542c7f7f8>

#1

Hi all,

I found the script below on the old imagej.1557.x6.nabble forum, and it does almost exactly what I need it to, but works on RGB images rather than 8-bit images. For my project I have to extract data from large no.s of ROIs and I hit limitations in data handling capacity, so switching from RGB to 8-bit images would reduce the amount of data by 66% and solve my problem as well as make the process faster. Would someone be able to rewrite this code to do so? I hope this is a fairly simple request, I have nigh on 0 knowledge in coding and my simplistic attempts to rewrite were quite futile.

Cheers,
John

Link to original code

import ij.*; 
import ij.process.*; 
import ij.gui.*; 
import java.awt.*; 
import ij.plugin.*; 
import ij.plugin.frame.*; 

public class MultiROIhist_ implements PlugIn { 

        public void run(String arg) { 
                ImagePlus imp = IJ.getImage(); 
                IJ.run(imp, "Invert", ""); 
                IJ.wait(1000); 
                IJ.run(imp, "Invert", ""); 
        } 

imp = IJ.getImage(); 
  ip = imp.getProcessor(); 
  rm = RoiManager.getInstance(); 
  rois = rm.getRoisAsArray(); 
  rt = new ResultsTable(); 
  for (i=0; i<rois.length; i++) { 
     ip.setRoi(rois[i]); 
     ip.setRGBWeights(1, 0, 0); 
     histogram = ip.getHistogram(); 
     rt.incrementCounter(); 
     rt.addValue("ROI", "R"+i); 
     for (j=0; j<256; j++) 
        rt.addValue("C"+j, histogram[j]); 
     ip.setRGBWeights(0, 1, 0); 
     histogram = ip.getHistogram(); 
     rt.incrementCounter(); 
     rt.addValue("ROI", "G"+i); 
     for (j=0; j<256; j++) 
        rt.addValue("C"+j, histogram[j]); 
     ip.setRGBWeights(0, 0, 1); 
     histogram = ip.getHistogram(); 
     rt.incrementCounter(); 
     rt.addValue("ROI", "B"+i); 
     for (j=0; j<256; j++) 
        rt.addValue("C"+j, histogram[j]); 
  } 
  rt.showRowNumbers(false); 
  rt.show("Results"); 

}

#2

Dear @WreckJohnB,

were you able to solve the issue in the meantime? If not, could you please explain in a bit more detail what you are trying to achieve?

Best,
Stefan