001package plugins.tutorial.training; 002 003import icy.gui.dialog.MessageDialog; 004import icy.plugin.abstract_.PluginActionable; 005import icy.roi.BooleanMask2D; 006import icy.sequence.Sequence; 007import icy.type.collection.array.Array1DUtil; 008import plugins.kernel.roi.roi2d.ROI2DArea; 009 010public class ThresholdPlugin2 extends PluginActionable 011{ 012 @Override 013 public void run() 014 { 015 // get the current sequence having focus. 016 Sequence sequence = getActiveSequence(); 017 018 // check if a sequence is opened 019 if (sequence == null) 020 { 021 MessageDialog.showDialog("Please open a sequence to use this plugin.", MessageDialog.WARNING_MESSAGE); 022 return; 023 } 024 025 // fixed threshold value 026 int threshold = 40; 027 028 // consider first image and first channel only here 029 double[] doubleArray = Array1DUtil.arrayToDoubleArray(sequence.getDataXY(0, 0, 0), sequence.isSignedDataType()); 030 boolean[] mask = new boolean[doubleArray.length]; 031 032 for (int i = 0; i < doubleArray.length; i++) 033 mask[i] = (doubleArray[i] >= threshold); 034 035 BooleanMask2D mask2d = new BooleanMask2D(sequence.getBounds2D(), mask); 036 ROI2DArea roi = new ROI2DArea(mask2d); 037 038 sequence.addROI(roi); 039 } 040 041}