Class Histogram1DCreator
java.lang.Object
net.sourceforge.jiu.ops.Operation
net.sourceforge.jiu.color.analysis.Histogram1DCreator
This class creates one-dimensional histograms for images with integer samples.
Only
IntegerImage
objects are supported.
Existing histogram objects can be given to this operation to be reused.
Give an existing Histogram1D
object to this operation via
setHistogram(Histogram1D)
.
The histogram can be created for any channel of an IntegerImage.
The first channel (index 0) is the default channel.
Use setImage(IntegerImage, int)
to specify another one.
Note: Before JIU 0.10.0 there was a single HistogramCreator class.
Usage example
Creates a histogram for the third channel of an image, whose index is two because channels are zero-based:Histogram1DCreator hc = new Histogram1DCreator(); hc.setImage(image, 2); hc.process(); Histogram1D hist = hc.getHistogram();If you just want to learn the number of different samples in an image, there's a static convenience method count for that. Again, we use the third channel:
Integer numUsedSamples = Histogram1DCreator.count(image, 2);
- Since:
- 0.10.0
- Author:
- Marco Schmidt
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Integer
count
(IntegerImage image) Static convenience method to count the number of different samples in the first channel of the argument image.static Integer
count
(IntegerImage image, int channelIndex) Static convenience method to count the number of different samples in one of the channels of the argument image.private void
Returns the histogram used in this operation.void
process()
This method does the actual work of the operation.void
setHistogram
(Histogram1D histogram) Sets a histogram object to be used for this operation.void
setImage
(IntegerImage newImage) Set the image for which the histogram is to be initialized.void
setImage
(IntegerImage newImage, int imageChannelIndex) Set the image and the channel index for which the histogram is to be initialized.Methods inherited from class net.sourceforge.jiu.ops.Operation
addProgressListener, addProgressListeners, getAbort, removeProgressListener, setAbort, setProgress, setProgress
-
Field Details
-
hist
-
channelIndex
private int channelIndex -
image
-
-
Constructor Details
-
Histogram1DCreator
public Histogram1DCreator()
-
-
Method Details
-
count
Static convenience method to count the number of different samples in the first channel of the argument image.- Parameters:
image
- the IntegerImage to be examined- Returns:
- the number of different values or null on failure
(image is
null
, histogram data structure could not be allocated) - Since:
- 0.15.0
-
count
Static convenience method to count the number of different samples in one of the channels of the argument image.- Parameters:
image
- the IntegerImage to be examinedchannelIndex
- the zero-based index of the channel to use- Returns:
- the number of different values or null on failure
(image is
null
, channel index is invalid, histogram data structure could not be allocated) - Since:
- 0.15.0
-
createHistogramIfNecessary
private void createHistogramIfNecessary() -
getHistogram
Returns the histogram used in this operation.- Returns:
- histogram object, newly-created or reused one
- See Also:
-
process
Description copied from class:Operation
This method does the actual work of the operation. It must be called after all parameters have been given to the operation object.- Overrides:
process
in classOperation
- Throws:
MissingParameterException
- if any mandatory parameter was not given to the operationWrongParameterException
- if at least one of the input parameters was not initialized appropriately (values out of the valid interval, etc.)
-
setHistogram
Sets a histogram object to be used for this operation. Withinprocess()
it will be checked if this histogram is large enough for the image.- See Also:
-
setImage
Set the image for which the histogram is to be initialized. The first channel (index 0) is used by default.- Parameters:
newImage
- image object to be used- See Also:
-
setImage
Set the image and the channel index for which the histogram is to be initialized.- Parameters:
newImage
- image object to be usedimageChannelIndex
- must not be negative and must be smaller than newImage.getNumChannels()- See Also:
-