A ’BGR’ image.
30 views (last 30 days)
Constantino Carlos Reyes-Aldasoro on 8 Sep 2021
First, changing channels is very simple you just need to change the third dimension of the image, e.g.
Now, let's change channels from RGB to BGR:
image2(:,:,1) = image1(:,:,3);
image2(:,:,2) = image1(:,:,2);
image2(:,:,3) = image1(:,:,1);
Now in terms of the filtering with a Gaussian, if you apply a 3x3 to every channel, that would be the same if you do in RGB or in BGR as you are averaging pixels in a channel.
Hope that answers your question.
More Answers (1)
Image Analyst on 9 Sep 2021
Ben, you can use imgaussfilt(). It's very straightforward but let us know if you can't figure out my code below.
clc; % Clear the command window.
workspace; % Make sure the workspace panel is showing.
format short g;
fontSize = 15;
fprintf('Beginning to run %s.m ...\n', mfilename);
rgbImage = imread('peppers.png');
subplot(2, 1, 1);
title('Original Image', 'FontSize', fontSize);
% Split into channels.
[r, g, b] = imsplit(rgbImage);
% Blur each channel.
sigma = 9; % Whatever.
smoothr = imgaussfilt(r, sigma);
smoothg = imgaussfilt(g, sigma);
smoothb = imgaussfilt(b, sigma);
% Combine individual blurred color channels into a new RGB image.
blurredImage = cat(3, smoothr, smoothg, smoothb);
% Display the blurred image.
subplot(2, 1, 2);
caption = sprintf('Blurred with a sigma of %.1f', sigma);
title(caption, 'FontSize', fontSize);