We are about to switch to a new forum software. Until then we have removed the registration on this forum.
import processing.video.*;
Capture video;
PImage frog;
public static final int[][] mask = {{1, 1, 1},
{1, 1, 1},
{1, 1, 1} };
void setup()
{
size(640,480);
video = new Capture(this,640,480);
video.start();
frog = loadImage("frog.jpg");
}
void captureEvent(Capture video){
video.read();
}
void draw()
{
loadPixels();
video.loadPixels();
frog.loadPixels();
for(int x=1;x+1<video.width;x++)
{
for(int y=1;y+1<video.height;y++)
{
int loc = x+y*video.width;
color value = applyBlur(video,x,y,mask);
pixels[loc] = value;
}
}
updatePixels();
}
color applyBlur(Capture video,int x,int y,int[][] mask)
{
int red=0,green=0,blue=0;
for(int j=-1;j<=1;j++)
{
for(int k=-1;k<=1;k++)
{
red += mask[1+j][1+k]*(red(video.get(x+k,y+j)));
green +=mask[1+j][1+k]*(green(video.get(x+k,y+j)));
blue += mask[1+j][1+k]*(blue(video.get(x+k,y+j)));
}
}
red = red/findSum(mask);
green = green/findSum(mask);
blue = blue/findSum(mask);
color value = color(red,green,blue);
return value;
}
int findSum(int[][] mask)
{
int sum=0;
for(int y=0;y<mask.length;y++)
{
for(int x=0;x<mask[y].length;x++)
{
sum += mask[y][x];
}
}
return sum;
}
Answers
Your convolution matrix, mask, is all ones...
Oh, OK, my mistake.
https://en.m.wikipedia.org/wiki/Kernel_(image_processing)
This doesn't look right
The way you use j first in mask and the k first in the get, but in reality all you've done is flipped the convolution matrix, which is symmetrical anyway, so it isn't a problem here.
Will have a better look when I'm not on my phone
Possible integer division problem in lines 61-63
What exactly is the problem occurring?
ok, that is generally sound, but the effect is very subtle and hard to see because of the fact it's video. if you use a still image then it's easier to see, so i've changed your code to do just one image.
the applyBlur does exactly the same thing as yours does but i've optimised it a bit, (but not completely) - there's no point in calling findsum() 3 times for ever pixel because it doesn't change (call it once and store it in a variable - factor). and i've renamed your red, green, blue variables because they clash with the names of methods.
it's faster but still very slow.