HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavaMinor

Gaussian blur - convolution algorithm

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
algorithmconvolutionblurgaussian

Problem

My program uses graphics convolution, an algorithm that processes pixels to make them round, soft and blurred. This particular algorithm is well-known, but its slowing down the operation of the whole program.

Can you suggest any improvements of this algorithm? I tried following from here, especially "ultimate solution" all the way to the bottom of that page, hoping to reduce the number of for loops one within another, but it did not work.

```
import perceptron.DoubleBuffer.ImageRenderContext;
import util.ColorUtility;
import java.awt.image.DataBuffer;

public final class Convolution {

DoubleBuffer buffer;
int[] d;
int s, h, e;
int[] temp;

/**
* Constructs new Convolution using the convolution degree and DoubleBuffer as input parameters.
*
* @param std
* @param b
*/
public Convolution(int std, DoubleBuffer b) {
s = 2 * std;
h = s / 2;
e = 256 / h;
d = new int[s];
buffer = b;
for (int i = 0; i > 32);
final long tmp2 = (long) (b * (tmp - 1072632447) + 1072632447);
return Double.longBitsToDouble(tmp2 > 8;
}
}
// Do Y blur
i = 0;
int notamount = 256 - amount;
for (int y = 0; y > 8;
int c2 = sourcebuffer.getElem(i) > 16) & 0x1fe) - ((c1 >> 16) & 0xff);
int g = ((c2 >> 8) & 0x1fe) - ((c1 >> 8) & 0xff);
int b = ((c2) & 0x1fe) - ((c1) & 0xff);
r = r 0xff ? 0xff : r;
g = g 0xff ? 0xff : g;
b = b 0xff ? 0xff : b;
c2 = (r > 8;
int c2 = sourcebuffer.getElem(i) > 16) & 0x1fe) - ((c1 >> 16) & 0xff);
int g = ((c2 >> 8) & 0x1fe) - ((c1 >> 8) & 0xff);
int b = ((c2) & 0x1fe) - ((c1) & 0xff);
r = r 0xff ? 0xff : r;
g = g 0xff ? 0xff : g;

Solution

Naming naming naming

Your code is very intimidating - it is filled with single letter variable and members (s,h,e,d...). Those which are not single letter are generic and unhelpful (temp, buffer, notamount...). This makes your code very unreadable.

You also use a lot of literal numbers (2, 256, 1072632447, 60801...) which make no sense to a person who is not familiar with your algorithm. Use constants to make your code more readable.

Your comments are also not useful for someone to read and understand your code.

If you want a serious code review, you must make your code readable, break large methods (operate) into smaller ones, etc.

Context

StackExchange Code Review Q#39592, answer score: 3

Revisions (0)

No revisions yet.