A ’BGR’ image.

조회 수: 28 (최근 30일)
Ben Ma
Ben Ma 2021년 9월 8일
답변: Image Analyst 2021년 9월 9일
a 3x3 Gaussian filter with BGR image Thanks.

채택된 답변

Constantino Carlos Reyes-Aldasoro
Hello:
First, changing channels is very simple you just need to change the third dimension of the image, e.g.
image1=imread('peppers.png');
imagesc(image1)
Now, let's change channels from RGB to BGR:
image2(:,:,1) = image1(:,:,3);
image2(:,:,2) = image1(:,:,2);
image2(:,:,3) = image1(:,:,1);
imagesc(image2)
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.
  댓글 수: 2
Ben Ma
Ben Ma 2021년 9월 9일
Can you also apply a 3x3 Gaussian filter to the original RGB image please? thanks
Constantino Carlos Reyes-Aldasoro
Yes, you can apply the filter to the original or to the transformed. E.g. to apply to the RGB you do the following:
image1=imread('peppers.png');
image1_filtered = imfilter(image1, fspecial('Gaussian',3,1));
figure
subplot(221)
imagesc(image1)
subplot(222)
imagesc(image1_filtered)
subplot(223)
imagesc(image1(100:150,100:150,:))
subplot(224)
imagesc(image1_filtered(100:150,100:150,:))
If you want to apply to the transformed, do the same once it has been transformed.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2021년 9월 9일
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.
clear all;
close all;
workspace; % Make sure the workspace panel is showing.
format short g;
format compact;
fontSize = 15;
fprintf('Beginning to run %s.m ...\n', mfilename);
rgbImage = imread('peppers.png');
subplot(2, 1, 1);
imshow(rgbImage);
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);
imshow(blurredImage);
caption = sprintf('Blurred with a sigma of %.1f', sigma);
title(caption, 'FontSize', fontSize);

카테고리

Help CenterFile Exchange에서 Image Processing and Computer Vision에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by