001/** 002 * 003 */ 004package plugins.kernel.roi.descriptor.intensity; 005 006import icy.roi.ROI; 007import icy.roi.ROIDescriptor; 008import icy.sequence.Sequence; 009import icy.sequence.SequenceEvent; 010import icy.sequence.SequenceEvent.SequenceEventSourceType; 011 012/** 013 * Standard Deviation intensity ROI descriptor class (see {@link ROIDescriptor}) 014 * 015 * @author Stephane 016 */ 017public class ROIStandardDeviationDescriptor extends ROIDescriptor 018{ 019 public static final String ID = "Standard deviation"; 020 021 public ROIStandardDeviationDescriptor() 022 { 023 super(ID, "Standard Deviation", Double.class); 024 } 025 026 @Override 027 public String getDescription() 028 { 029 return "Standard deviation"; 030 } 031 032 @Override 033 public boolean separateChannel() 034 { 035 return true; 036 } 037 038 @Override 039 public boolean needRecompute(SequenceEvent change) 040 { 041 return (change.getSourceType() == SequenceEventSourceType.SEQUENCE_DATA); 042 } 043 044 @Override 045 public Object compute(ROI roi, Sequence sequence) throws UnsupportedOperationException 046 { 047 return Double.valueOf(computeStandardDeviation(roi, sequence)); 048 } 049 050 /** 051 * Computes and returns the compute standard deviation for the specified ROI on given sequence.<br> 052 * It may returns <code>Double.Nan</code> if the operation is not supported for that ROI. 053 * 054 * @param roi 055 * the ROI on which we want to compute the standard deviation 056 * @param sequence 057 * the sequence used to compute the pixel intensity 058 * @throws UnsupportedOperationException 059 * if the operation is not supported for this ROI 060 */ 061 public static double computeStandardDeviation(ROI roi, Sequence sequence) throws UnsupportedOperationException 062 { 063 try 064 { 065 return ROIIntensityDescriptorsPlugin.computeIntensityDescriptors(roi, sequence, false).deviation; 066 } 067 catch (Exception e) 068 { 069 throw new UnsupportedOperationException(ROIStandardDeviationDescriptor.class.getSimpleName() + ": cannot compute descriptors for '" 070 + roi.getName() + "'", e); 071 } 072 } 073}