001package plugins.tutorial.training; 002 003import icy.gui.dialog.MessageDialog; 004import icy.image.IcyBufferedImage; 005import icy.plugin.abstract_.PluginActionable; 006import icy.sequence.Sequence; 007import plugins.kernel.roi.roi2d.ROI2DArea; 008 009public class ThresholdPlugin1 extends PluginActionable 010{ 011 @Override 012 public void run() 013 { 014 // get the current sequence having focus. 015 Sequence sequence = getActiveSequence(); 016 017 // check if a sequence is opened 018 if (sequence == null) 019 { 020 MessageDialog.showDialog("Please open a sequence to use this plugin.", MessageDialog.WARNING_MESSAGE); 021 return; 022 } 023 024 // fixed threshold value 025 int threshold = 40; 026 027 ROI2DArea roi = new ROI2DArea(); 028 // consider first image only here 029 IcyBufferedImage image = sequence.getFirstImage(); 030 031 for (int x = 0; x < sequence.getSizeX(); x++) 032 { 033 for (int y = 0; y < sequence.getSizeY(); y++) 034 { 035 if (image.getData(x, y, 0) >= threshold) 036 { 037 roi.addPoint(x, y); 038 } 039 } 040 } 041 042 sequence.addROI(roi); 043 } 044 045}