Trying to blur a picture in Jython. What I have does run but does not return a blurred picture. I'm kinda at a loss of what is wrong with it.
FINAL (WORKING) CODE EDITED IN BELOW. THANKS FOR HELP GUYS!
pic= makePicture( pickAFile() )
show( pic )
blurPic= makeEmptyPicture( w-blurAmount, h )
for px in getPixels(blurPic):
for i in range(0,blurAmount):
for loop, looping through all the pixels (in blurPic)
get and save x and y locations of the pixel
#make sure you are not too close to edge (x+blur) is less than width
Intialize rTotal, gTotal, and bTotal to 0
# add up the rgb values for all the pixels in the blur
For loop that loops (blur_amount) times
rTotal= rTotal +the red pixel amount of the picture (input argument) at the location (x+loop number,y) then same for green and blue
find the average of red,green, blue values, this is just rTotal/blur_amount (same for green, and blue)
set the red value of blurPic pixel to the redAverage (same for green and blue)
The problem is that you are overwriting the variable
px from the outer loop which is the pixel in the blurred image with a pixel value from the original image.
So just replace your inner loop with:
for i in range(0,blurAmount): origPx=getPixel(pic,x+i,y) rTotal=rTotal+getRed(origPx) gTotal=gTotal+getGreen(origPx) bTotal=bTotal+getBlue(origPx)
In order to show the blurred picture change the last line in you
show( makeBlurredPicture(pic,blurAmount) )