Average blurring mask produces different results

multiplying each pixel by the average blurring mask *(1/9) but the result is totally different.

PImage toAverageBlur(PImage a) { PImage aBlur = new PImage(a.width, a.height); aBlur.loadPixels(); for(int i = 0; i < a.width; i++) { for(int j = 0; j < a.height; j++) { int pixelPosition = i*a.width + j; int aPixel = ((a.pixels[pixelPosition] /9)); aBlur.pixels[pixelPosition] = color(aPixel); } } aBlur.updatePixels(); return aBlur; }

-------------Problems Reply------------

Currently, you are not applying an average filter, you are only scaling the image by a factor of 1/9, which would make it darker. Your terminology is good, you are trying to apply a 3x3 moving average (or neighbourhood average), also known as a boxcar filter.

For each pixel i,j, you need to take the sum of (i-1,j-1), (i-1,j), (i-1,j+1), (i,j-1), (i,j),(i,j+1),(i+1,j-1),(i+1,j),(i+1,j+1), then divide by 9 (for a 3x3 average). For this to work, you need to not consider the pixels on the image edge, which do not have 9 neighbours (so you start at pixel (1,1), for example). The output image will be a pixel smaller on each side. Alternatively, you can mirror values out to add an extra line to your input image which will make the output image the same size as the original.

There are more efficient ways of doing this, for example using FFT based convolution; these methods are faster because they don't require looping.

Category:image processing Views:0 Time:2011-03-26

Related post

  • Averaging columns produce erroneous results after row377 2013-06-07

    Hi all... I hope someone has a solution to this as it is now driving me up the wall. I am wanting to average a column of percentages based on two criteria. My table look as follows. Column "D" has dates extending down on a daily basis from row 6 to r

  • What command produces the results listed below. 2013-07-27

    \Hamlet - Dell Dimension 2350 Desktop - Ethernet adapter Local Area Connection: Connection-specific DNS Suffix . : AR430W Description . . . . . . . . . . . : Broadcom 440x 10/100 Integrated Controller Physical Address. . . . . . . . . :

  • Dynamic linq:Creating an extension method that produces JSON result 2008-09-08

    I'm stuck trying to create a dynamic linq extension method that returns a string in JSON format - I'm using System.Linq.Dynamic and Newtonsoft.Json and I can't get the Linq.Dynamic to parse the "cell=new object[]" part. Perhaps too complex? Any ideas

  • Which javascript minification library produces better results? 2008-12-11

    Between Yahoo! UI Compressor, Dean Edwards Packer and jsmin, which produces better results, both in terms of resulting footprint and fewer errors when obfuscating. --------------Solutions------------- Better is a bit subjective here, since there are

  • Why does my Linq Where clause produce more results instead of less? 2009-05-06

    I just had the weirdest debug experience in a very long time. It's a bit embarassing to admit, but it lead me to be believe that my Linq query produces MORE results when adding an additional Where clause. I know it's not possible, so I've refactored

  • Visual Studio 2008 Profiler - Instrumented produces strange results 2009-08-31

    I run the Visual Studio 2008 profiler on a "RelDebug" build of my app. Optimizations are on, but inlining is only moderate, stack frames are present, and symbols are emitted. In other words, RelDebug is a somewhat optimized build that can be debugged

  • Hide filter items that produce zero results in django-filter 2010-02-02

    I have an issue with the django-filter application: how to hide the items that will produce zero results. I think that there is a simple method to do this, but idk how. I'm using the LinkWidget on a ModelChoiceFilter, like this: provider = django_fil

  • while using g.drawImage(img,0,0,100,100,0,0,0,0,null) it does not produce any result? 2010-02-23

    while using g.drawImage(img,0,0,100,100,0,0,0,0,null) it does not produce any result. So how to draw on the image in file of a better way? --------------Solutions------------- As well as ensuring the image is loaded, the last 4 int parameters are the

  • Why is my SQL 'NOT IN' clause producing different results from 'NOT EXISTS' 2010-06-04

    I have two SQL queries producing different results when I would expect them to produce the same result. I am trying to find the number of events that do not have a corresponding location. All locations have an event but events can also link to non-lo

  • Clean blur mask over an image by finger 2010-10-04

    I want to create an ImageView with a blur mask over it. And user can use his finger to clean the mask and view origin pic under it. Is there any library for that purpose? Thanks.

  • Which encryption method would produce this result 2010-10-09

    I am doing a security review on a system. From one part of the system to another, information is sent using an encrypted string. This string is over 400 characters long, but within it are 4 sets of 10 identical characters. I am assuming that the data

  • Why does gmp_mod produce differerent results on different platforms? 2010-12-10

    Please consider this snippet (related to How is 13 % 64= -13) if(extension_loaded('GMP')) { printf(" PHP Version: %s gmp_strval(gmp_mod('-13', '64')) = %s gmp_strval(gmp_mod(-13, 64)) = %s gmp_mod(-13, 64) = %s ", phpversion(), gmp_strval(gmp_mod('-1

  • Why python IDLE and Console produce different results 2010-12-31

    I write a simple Python script to translate Chinese Punctuation to English. import codecs, sys def trcn(): tr = lambda x: x.translate(str.maketrans(""",。!?;:、()【】『』「」﹁﹂“”‘’《》~¥…—×""", """,.!?;:,()[][][][]""''<>~$^-*""")) out = codecs.getwriter(

  • ruby: converting from float to integer in ruby produces strange results 2011-03-10

    ree-1.8.7-2010.02 :003 > (10015.8*100.0).to_i => 1001579 ree-1.8.7-2010.02 :004 > 10015.8*100.0 => 1001580.0 ree-1.8.7-2010.02 :005 > 1001580.0.to_i => 1001580 ruby 1.8.7 produces the same. Does anybody knows how to eradicate this h

  • sorting and updating datatable not producing expected results 2011-03-31

    EDIT: Solved this myself - obviously won't work as sorting the dataTable doesn't sort the underlying data - created a dataView from the table, works fine. I have a datatable which I am sorting and then iterating through to remove duplicate values in

  • HTML5 CSS3/Javascript Blur Mask 2011-04-04

    There are many of us looking for a Javascript/CSS3 solution that can provide a windows7-like UI within a webpage, without using flash. We need an Opacity mask, rounded borders, and a Blur... We've got the Opacity and the rounded borders, now we need

  • Why does Path.Combine produce this result with a relative path? 2011-04-21

    To my surprise, this code does not produce expected results: var basePath = @"\\server\BaseFolder"; var relativePath = @"\My\Relative\Folder"; var combinedPath = Path.Combine(basePath, relativePath); The result is \My\Relative\Folder instead of the e

  • Split Entity mapping producing unexpected results with oracle database 2011-07-20

    i am currently using the following mapping to map a split entity and is producing unexpeted results it is trying to map a table public class TestResultMap : EntityTypeConfiguration { public TestResultMap() { #region Property => Column Mapping //te

  • why the sleep statement produces this result for our embedded ruby? 2011-09-06

    We are testing thread coperation for our embedded ruby. We have a C ruby extension implementented the following methods 1. longRunningMethod() 2. shortRunningMethod(). Here is a code for the checking the thread cooperation //file test.rb require 'mym

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.123 (s). 11 q(s)