|
JIU 0.14.3 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sourceforge.jiu.ops.Operation
net.sourceforge.jiu.ops.ImageToImageOperation
net.sourceforge.jiu.color.reduction.RGBToGrayConversion
public class RGBToGrayConversion
Converts RGB color images (both truecolor and paletted) to grayscale images.
The weights to be used with the three base colors red, green and blue can be
modified with a call to
setColorWeights(float, float, float)
.
RGB24Image
and Paletted8Image
can be used as input image types.
A Gray8Image
be will be created from them.
Could be optimized to use int multiplication instead of float multiplication.
PixelImage grayImg = RGBToGrayConversion.convert(rgbImage);Using your own color weights can be done like this. You may also want to specify an output grayscale image if you have one to reuse.
RGBToGrayConversion rgbtogray = new RGBToGrayConversion(); rgbtogray.setInputImage(image); rgbtogray.setColorWeights(0.3f, 0.3f, 0.4f); rgbtogray.process(); PixelImage grayImage = rgbtogray.getOutputImage();
Field Summary | |
---|---|
static float |
DEFAULT_BLUE_WEIGHT
The default weight for blue samples in the conversion, 0.11f. |
static float |
DEFAULT_GREEN_WEIGHT
The default weight for green samples in the conversion, 0.59f. |
static float |
DEFAULT_RED_WEIGHT
The default weight for red samples in the conversion, 0.3f. |
Constructor Summary | |
---|---|
RGBToGrayConversion()
|
Method Summary | |
---|---|
static PixelImage |
convert(PixelImage rgbImage)
Static convenience method to convert an RGB image to a grayscale image. |
void |
process()
This method does the actual work of the operation. |
void |
setColorWeights(float red,
float green,
float blue)
Sets the weights for the three colors red, green and blue used in the conversion procedure. |
Methods inherited from class net.sourceforge.jiu.ops.ImageToImageOperation |
---|
canInputAndOutputBeEqual, ensureImagesHaveSameResolution, ensureInputImageIsAvailable, ensureOutputImageResolution, getInputImage, getOutputImage, setCanInputAndOutputBeEqual, setInputImage, setOutputImage |
Methods inherited from class net.sourceforge.jiu.ops.Operation |
---|
addProgressListener, addProgressListeners, getAbort, removeProgressListener, setAbort, setProgress, setProgress |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final float DEFAULT_RED_WEIGHT
public static final float DEFAULT_GREEN_WEIGHT
public static final float DEFAULT_BLUE_WEIGHT
Constructor Detail |
---|
public RGBToGrayConversion()
Method Detail |
---|
public static PixelImage convert(PixelImage rgbImage) throws MissingParameterException, WrongParameterException
rgbImage
- input RGB image to be converted
MissingParameterException
- rgbImage is null
WrongParameterException
- rgbImage's type is unsupportedpublic void process() throws MissingParameterException, WrongParameterException
Operation
process
in class Operation
MissingParameterException
- if any mandatory parameter was not given to the operation
WrongParameterException
- if at least one of the input parameters was
not initialized appropriately (values out of the valid interval, etc.)public void setColorWeights(float red, float green, float blue)
(r, g, b)
to be converted (whether in a truecolor
image or in the palette), the formula is gray = r * red + g * green + b * blue
.
The default values for these weights are DEFAULT_RED_WEIGHT
,
DEFAULT_GREEN_WEIGHT
and DEFAULT_BLUE_WEIGHT
.
This method lets the user change these values.
Each of these arguments must be >= 0.0f and <= 1.0f.
The sum of the three must be <= 1.0f.
For any resulting gray value to be spread over the complete scale from 0.0f to 1.0f it is
preferable for the sum to be equal to or at least close to 1.0f.
However, this is not checked.
The smaller the sum of the weights is, the darker the resulting gray image will become.
red
- weight of the red sample in the conversion, between 0.0f
and 1.0f
green
- weight of the green sample in the conversion, between 0.0f
and 1.0f
blue
- weight of the blue sample in the conversion, between 0.0f
and 1.0f
IllegalArgumentException
- if any one of the above mentioned constraints for the arguments is not met
|
JIU 0.14.3 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |