Creating a blur brush tool for images
3 views (last 30 days)
Show older comments
Is it possible to create a blur brush tool for images , such as in photoshop:
I want that the user will decide what is the raduis of the circle, and after that the circle will follow the cursor over the image (the axis/figure).
After clicking twice , I want that the area of the image under the brush will be blured.
I am new in matlab and I need your help, full code will be great!
2 Comments
Rik
on 16 Feb 2022
Since the BlurBrush function doesn't exist, you will have to split this task into parts you can solve.
How do you think you can split up this tool into components? Which parts can you already implement on your own?
Answers (2)
DGM
on 26 Apr 2022
Doing the interactive painting routine sounds like it's going to be laggy and frustrating. That's one of the things I've long-avoided even attempting to incorporate into MIMT based on the assumption that it would be too laggy to be productive.
If you do manage to get a mask drawn, what next? I imagine this is why you asked the question about the restricted median filter application. I should point out a few things that you might want to consider in creating the mask and applying the filter. Let's start with a test image and a hard mask.
% an image
A = im2double(imread('a.png'));
% and a mask
mask = im2double(imread('mk.png'));
If we apply a simple gaussian blur via composition (similar to the median filter example), we get this:
% make a filtered copy
Afilt = imgaussfilt(A,5);
% compose output image
B = Afilt.*mask + A.*(1-mask);
imshow(B)
Obviously, the hard mask edges make this look terrible. This is exact same behavior as roifilt2().
If we soften the mask by blurring it (or by creating a soft mask to begin with), we get something that looks like this:
mask = imgaussfilt(mask,10); % soften the mask
% compose output image
B = Afilt.*mask + A.*(1-mask);
imshow(B)
That looks better, and note that this is something that roifilt2() cannot do. roifilt2() binarizes the mask and can only create hard-edged results like the first example. If you don't want hard mask transitions, you can't use roifilt2().
Back to the above example. Note the transition at the edge of the ROI. The crisp lines of the original image don't get progressively blurred; instead, they stay sharp as they fade away. The composition process only modulates the opacity, not the actual blur radius.
If you want something like a variable-size blur, I'm sure there are implementations around. A compromise might be something like MIMT pseudoblurmap().
A = im2double(imread('a.png'));
% make a soft mask
mask = im2double(imread('mk.png'));
mask = imgaussfilt(mask,10); % soften the mask
% blur it
B = pseudoblurmap(mask,A,'blursize',30);
imshow(B)
Compare the checkerboard edges in this example with the prior one. Here, the lines are progressively blurred.
Just some things to consider.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!