mergecv

Merges specified RGB/RGBA channels into a single image.

Syntax

handle = mergecv(r, g, b)

handle = mergecv(r, g, b, a)

handle = mergecv(m)

Inputs

r
Handle of the single channel image or a real, 2D matrix representing the red channel. An empty matrix ([]) can be used to supress red channel in handle.
Type: integer | mat
g
Handle of the single channel image or a real, 2D matrix representing the green channel. An empty matrix ([]) can be used to supress green channel in handle.
Type: integer | mat
b
Handle of the single channel image or a real, 2D matrix representing the blue channel. An empty matrix ([]) can be used to supress blue channel in handle.
Type: integer | mat
a
Handle of the single channel image or a real, 2D matrix representing the alpha channel. An empty matrix ([]) can be used to supress alpha channel in handle.
Type: integer | mat
m
3D or 4D real matrix representing image data.
Type: n-dimensional matrix

Outputs

handle
Handle of the merged image.
Type: integer

Examples:

Merge an image with all channels specified:

cvhandle = imreadcv('image1.jpg');
[r, g, b] = splitcv(cvhandle);
mergedhandle = mergecv(r, g, b);
Merge an image, supressing the green and blue channels:

cvhandle = imreadcv('bird5.jpg');
[r, g, b] = splitcv(cvhandle);
mergedhandle = mergecv(r, [], []); % Shows only the red channel


Figure 1. Input image


Figure 2. Output image
Merge the RGB channels and create one merged image:
%Read image
img = imreadcv('RGBchannels.jpg',1);

[blue, green, red] = splitcv(img);

figure(1);
imshowcv(blue);

figure(2);
imshowcv(red);

figure(3);
imshowcv(green);

merged = mergecv(red,green,blue);

figure(4);
imshowcv(merged);


Figure 3. Blue channel


Figure 4. Red channel


Figure 5. Green channel


Figure 6. Merged image
Merge an image, supressing the blue channel and modifying the green channel:

cvhandle = imreadcv('image1.jpg');
[r, g, b] = splitcv(cvhandle);
imsize = imsizecv(r);
mergedhandle = mergecv(r, ones(imsize(1),imsize(2)), []);
Merge an image using a 3D matrix:

cvhandle = imreadcv('bird5.jpg');
m = getcv(cvhandle);
m(:,:,1) = 0; % Modify the image data
R = mergecv(m);


Figure 7. Input image


Figure 8. Output image