Main Content

jitterColorHSV

Randomly alter color of pixels

Description

J = jitterColorHSV(I,Name=Value) adjusts the color of RGB image 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 arguments.

example

Examples

collapse all

Read and display an image.

I = imread("kobi.png");
imageshow(I)

Randomly adjust the contrast, hue, saturation, and brightness of the image. To demonstrate the randomness of the adjustment, repeat the operation on the original image three times.

c = 0.4;
h = 0.1;
s = 0.2;
b = 0.3;
J1 = jitterColorHSV(I,Contrast=c,Hue=h,Saturation=s,Brightness=b);
J2 = jitterColorHSV(I,Contrast=c,Hue=h,Saturation=s,Brightness=b);
J3 = jitterColorHSV(I,Contrast=c,Hue=h,Saturation=s,Brightness=b);

Display the adjusted images in a montage. Each image shows a different adjustment to the contrast, hue, saturation, and brightness.

montage({J1,J2,J3},Size=[1 3])

Figure contains an axes object. The hidden axes object contains an object of type image.

Input Arguments

collapse all

RGB image with original pixel values, specified as an m-by-n-by-3 numeric array.

Data Types: single | double | uint8 | uint16

Name-Value Arguments

collapse all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: J = jitterColorHSV(I,Hue=0.1) adds a random amount of hue from the uniform distribution [-0.1, 0.1].

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: J = jitterColorHSV(I,"Hue",0.1) adds a random amount of hue from the uniform distribution [-0.1, 0.1].

Hue offset, specified as 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.

ValueMeaning
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 offset, specified as 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.

ValueMeaning
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 offset, specified as 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.

ValueMeaning
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 scale factor, specified as 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.

ValueMeaning
Positive numberScale the brightness by a random factor from the uniform distribution [1-Contrast 1+Contrast]
2-element numeric vector of positive numbersScale 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

Output Arguments

collapse all

Jittered 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

More About

collapse all

Version History

Introduced in R2019b