Randomly alter color of pixels
adjusts the color of RGB image J
= jitterColorHSV(I
,Name,Value
)I
with a randomly selected value of hue,
saturation, brightness, and contrast from the HSV color space. Specify the range
of each type of adjustment using name-value pair arguments.
Read and display an image.
I = imread('kobi.png');
imshow(I)
Randomly adjust the hue, saturation, brightness, and contrast of the image. To demonstrate the randomness of the adjustment, repeat the operation on the original image three times.
J1 = jitterColorHSV(I,'Contrast',0.4,'Hue',0.1,'Saturation',0.2,'Brightness',0.3); J2 = jitterColorHSV(I,'Contrast',0.4,'Hue',0.1,'Saturation',0.2,'Brightness',0.3); J3 = jitterColorHSV(I,'Contrast',0.4,'Hue',0.1,'Saturation',0.2,'Brightness',0.3);
Display the adjusted images in a montage.
montage({J1,J2,J3},'Size',[1 3])
I
— RGB imageRGB image with original pixel values, specified as an m-by-n-by-3 numeric array.
Data Types: single
| double
| uint8
| uint16
Specify optional
comma-separated pairs of Name,Value
arguments. Name
is
the argument name and Value
is the corresponding value.
Name
must appear inside quotes. You can specify several name and value
pair arguments in any order as
Name1,Value1,...,NameN,ValueN
.
J = jitterColorHSV(I,'Hue',0.1)
'Hue'
— Hue offset0
(default) | numeric scalar | 2-element numeric vectorHue offset, specified as the comma-separated pair consisting of
'Hue'
and one of the following values.
jitterColorHSV
converts input RGB image I
to the HSV color space before adding a random value to the hue channel of the image.
jitterColorHSV
circularly wraps the modified hue to the range [0,
1] before converting the jittered HSV image back to the RGB color space.
Value | Meaning |
---|---|
Numeric scalar in the range [0, 1] | Add random amount of hue from the uniform distribution [-Hue
Hue] |
2-element numeric vector with elements in the range [-1, 1] | Add a random amount of hue from a continuous uniform distribution within the specified interval. The second element must be larger than or equal to the first element. |
Data Types: single
| double
'Saturation'
— Saturation offset0
(default) | numeric scalar | 2-element numeric vectorSaturation offset, specified as the comma-separated pair consisting of
'Saturation'
and one of the following values.
jitterColorHSV
converts input RGB image I
to the HSV color space before adding a random value to the saturation channel of the
image. jitterColorHSV
clips the modified saturation to the range
[0, 1] before converting the jittered HSV image back to the RGB color space.
Value | Meaning |
---|---|
Numeric scalar in the range [0, 1] | Add random amount of saturation from the uniform distribution
[-Saturation Saturation] |
2-element numeric vector with elements in the range [-1, 1] | Add a random amount of saturation from a continuous uniform distribution within the specified interval. The second element must be larger than or equal to the first element. |
Data Types: single
| double
'Brightness'
— Brightness offset0
(default) | numeric scalar | 2-element numeric vectorBrightness offset, specified as the comma-separated pair consisting of
'Brightness'
and one of the following values.
jitterColorHSV
converts input RGB image I
to the HSV color space before adding a random value to the brightness (value) channel
of the image. jitterColorHSV
clips the modified brightness to the
range [0, 1] before converting the jittered HSV image back to the RGB color
space.
Value | Meaning |
---|---|
Numeric scalar in the range [0, 1] | Add random amount of brightness from the uniform distribution
[-Brightness Brightness] |
2-element numeric vector with elements in the range [-1, 1] | Add a random amount of brightness from a continuous uniform distribution within the specified interval. The second element must be larger than or equal to the first element. |
Data Types: single
| double
'Contrast'
— Contrast scale factor0
(default) | positive number | 2-element numeric vectorContrast scale factor, specified as the comma-separated pair consisting of
'Contrast'
and one of the following values.
jitterColorHSV
converts input RGB image I
to the HSV color space before scaling the brightness (value) channel of the image by a
random factor. jitterColorHSV
clips the modified brightness to the
range [0, 1] before converting the jittered HSV image back to the RGB color
space.
Value | Meaning |
---|---|
Positive number | Scale the brightness by a random factor from the uniform distribution
[1-Contrast 1+Contrast] |
2-element numeric vector of positive numbers | Scale the brightness by a random factor from the uniform distribution within the specified interval. The second element must be larger than or equal to the first element. |
Data Types: single
| double
J
— Jittered RGB imageJittered RGB image, returned as a numeric array of the same size and data type as
the input image, I
.
Data Types: single
| double
| uint8
| uint16
The HSV color space defines the hue, saturation, and value (brightness) for each pixel, respectively, as described in the table.
Attribute | Description |
---|---|
Hue | Value from 0 to 1 that corresponds to
the color’s position on a color wheel. As hue increases from 0
to 1 , the color transitions from red to orange, yellow, green,
cyan, blue, magenta, and finally back to red. |
Saturation | Amount of hue or departure from neutral. 0 indicates a
grayscale image and 1 indicates maximum saturation. |
Value | Maximum value among the red, green, and blue components of a specific color. |
centerCropWindow2d
| hsv2rgb
| randomAffine2d
| randomCropWindow2d
| rgb2hsv
A modified version of this example exists on your system. Do you want to open this version instead?
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
Select web siteYou can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.