How to blur with a controlled area?

11 ビュー (過去 30 日間)
Billy
Billy 2012 年 11 月 21 日
回答済み: DGM 2022 年 6 月 22 日
Hello, I have to be able to blur only specific part of a .jpg, however the size needs to be about 200 pixels by 200 pixels with a threshold of about plus or minus 4 pixels. The hint my teacher gave was to change the color values into the average of the surrounding plus or minus 4 color values. The last step is to recombine these three new color layers. I have not learned how to manipulate a section of the color layers so that they are blurred, any help would be greatly appreciated.

採用された回答

Image Analyst
Image Analyst 2012 年 11 月 21 日
I don't know what that means. Do you mean that you might have a, say, 10 megapixel image but you want to blur only a 200x200 +/- 4? In other words, blur an area that's somewhere between 39,996 and 40,004 pixels? How would you specify where that small area is located inside your 10 megapixel image? Here's some code snippets that may be helpful
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Mask by some binary image.
maskedRed = redChannel .* mask;
maskedGreen = greenChannel .* mask;
maskedBlue = blueChannel .* mask;
% Recombine separate channels into a single RGB image.
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
maskedRgbImage = cat(3, maskedRed, maskedGreen, maskedBlue);
% Blur an image (average in a window)
blurredImage = conv2(redChannel, ones(windowWidth)/windowWidth^2, 'same');
Note: this is not a working script - it's just some snippets. See what you can get with those code statements I gave you. Write back with your program if you need more hints.
I'm not sure what it means to change a pixel into the average of the surrounding pixels plus or minus 4 color values. The pixel is either the average value or it's some other value, like the average+4 or the average-4, but you have to specify because the pixel has to have one value, not a range of values.
  28 件のコメント
Billy
Billy 2012 年 11 月 22 日
Ya I got it to work all I needed to do was axis image. Thanks again.
Image Analyst
Image Analyst 2012 年 11 月 22 日
What Walter said was 100% accurate. axis image doesn't have anything to do with whether your image is the original image or the blurred image outside of your rectangular ROI. Though sometimes that (axis image) seems to change the aspect ratio, if your aspect ratio got changed for some reason.

サインインしてコメントする。

その他の回答 (1 件)

DGM
DGM 2022 年 6 月 22 日
If the user has Image Processing Toolbox, using roifilt2() or even imfilter()/imgaussfilt() could simplify the task. For a small ROI within a large image, using roifilt2() can avoid excess computations, but it's limited to strictly logical (hard) masking behavior. It tends to lose a lot of that speed advantage when processing RGB images since it has to process each channel independently due to the fact that it only supports single-channel inputs. Whether that's of concern is a question for you to decide.
An example of using roifilt2() on an RGB image can be found here:
An example of doing blurring (hard and soft masks) using basic composition methods and basic MATLAB/IPT tools can be found here:
An example of doing soft-masked blurring using purpose-built composition tools can be found here (the last face-blurring example):

カテゴリ

Help Center および File ExchangeComputer Vision with Simulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by