September 20, 2016

# Surface Blur and Median

Today, Photopea gets two new professional filters: Surface Blur filter and Median filter! Moreover, Photopea performs them much faster, than Photoshop and GIMP do, as you can see in the last section. See it in action at the main site.

## Surface Blur

Surface Blur filter, which is known as Surface Blur in Adobe Photoshop and as Selective Gaussian Blur in Gimp, is an advanced image filter. It can denoise images, while preserving edges. You can use it to fix noisy photos or smooth out areas with a similar color.

Try it now! (Filter - Blur - Surface Blur).

## Median Filter

Median filter is another very common filter, which reduces noise and preserves edges. It can fix pixels or even small areas with damaged or missing color.

Try it now! (Filter - Noise - Median).

## Performance and speed

TL;DR: Photopea uses a more advanced algorithm, which allows it to run faster, even though it is written in Javascript.

As a performance test, we tried to measure the time of computing Surface Blur with the Radius = 100 and the Threshold = 100 on a woman.jpg image (the previous example). Here are the results:

Image EditorTime
GIMP55 s
Photoshop2 s
Photopea0.6 s

Let's analyze it with science! The reason of such performance is the computational complexity of a method, that is used by each program. Each program has to work with an image having N pixels and compute the filter for a radius of R pixels. GIMP perfroms $N × R × R$ steps to compute the filter, while Photoshop performs $N × R$ steps only. When you increase the radius twice, Photoshop computation takes twice more time, but GIMP takes four times more time.

Photopea has two methods of computing the Surface Blur (or Median). First method performs $N × R$ steps and another one performs $N × 10$ steps (the time remains the same for any radius). When radius is at most 10, it performs the first method, otherwise it performs the second method. The computation time can be expressed by a following chart.

You can see, that for a radus of 10 pixels, Photopea is a lot slower than Photoshop, while both of them use the same method, that takes $N × R$ steps. The reason of such speed is, that Photoshop has a parallel, multi-threaded implementation, while Photopea runs in a single thread now.