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 * Mean intensity ROI descriptor class (see {@link ROIDescriptor}) 014 * 015 * @author Stephane 016 */ 017public class ROIMeanIntensityDescriptor extends ROIDescriptor 018{ 019 public static final String ID = "Mean intensity"; 020 021 public ROIMeanIntensityDescriptor() 022 { 023 super(ID, "Mean Intensity", Double.class); 024 } 025 026 @Override 027 public String getDescription() 028 { 029 return "Mean intensity"; 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(computeMeanIntensity(roi, sequence)); 048 } 049 050 /** 051 * Computes and returns the mean intensity 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 mean intensity 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 computeMeanIntensity(ROI roi, Sequence sequence) throws UnsupportedOperationException 062 { 063 try 064 { 065 return ROIIntensityDescriptorsPlugin.computeIntensityDescriptors(roi, sequence, false).mean; 066 } 067 catch (Exception e) 068 { 069 throw new UnsupportedOperationException(ROIMeanIntensityDescriptor.class.getSimpleName() + ": cannot compute descriptors for '" 070 + roi.getName() + "'", e); 071 } 072 } 073}