Creating a blur brush tool for images

13 views (last 30 days)
David Levi
David Levi on 16 Feb 2022
Answered: DGM on 26 Apr 2022
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!
David Levi
David Levi on 16 Feb 2022
blur - is attached, it includes what I have done (It is not complete but is is a start).
I wish to do the following steps:
  1. First you should press the load button for choosing an image and presenting it on the axis.
  2. You should use the spinner in order decide what is the raduis of the circle.
  3. Press the Brush button for drwing a circular roi that follows the cursor. ( I used iptSetPointerBehavior function for changing the roi location to the same location of the cursor).
All the above I have done.
The following steps should be added(This is the point I need your help):
4. If there is: mouse left-click + dragging : a binary mask will be created according to the mouse motion , and the mask will stop updating when the user releases the mouse left button.
5. In this point, after releasing the mask should be smoething like this: (Built from white circles)
6. Finally , I want to use fspecial function (one of the follows) for creating a blur filter.
and I want to applay this filter h , over the presented image , only in the white regoins of the mask. (use the J = roifilt2(h,I,BW) function).
please help me write this. The only problem is writing it as a code.

Sign in to comment.

Answers (2)

David Levi
David Levi on 26 Apr 2022
I dont want to open a new question on this. can you help me?

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);
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);
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);
Compare the checkerboard edges in this example with the prior one. Here, the lines are progressively blurred.
Just some things to consider.

Community Treasure Hunt

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

Start Hunting!