Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7787569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:42:46+00:00 2026-06-01T20:42:46+00:00

I am trying to create a guassian filter without using ConvolveOp. I am having

  • 0

I am trying to create a guassian filter without using ConvolveOp.
I am having a lot of problems trying to get this to work, i have gotten a grey scale filter to work, but for this one i am having problems finding the location of a pixels 8 neighbors, so i can apply the filter. here is what i have so far. Is this the right way to approach getting each of the pixels?

public class Gaussian implements Filter {


   public void filter(PixelImage pi) {
    Pixel[][] data = pi.getData();
    Pixel[][] original = data;


    int kernel_rows = 3;
    int kernel_cols = 3;

    // define kernel here (double loop), these are the 1/16, 2/16, etc...
    // values that you're multiplying the image pixels by
    double[][] kernel = {{1,2,1},
      {2,4,2},
      {1,2,1}};

    // iterate over each pixel in the image
    for (int row = 0; row < pi.getHeight(); row ++) {
      for (int col = 0; col < pi.getWidth(); col++) {
        // iterate over each pixel in the kernel
        for (int row_offset = 0 ; row_offset < kernel_rows ; row_offset++ ) {
          for (int col_offset = 0 ; col_offset < kernel_cols ; col_offset++ ) {

            // subtract by half the kernel size to center the kernel
            // on the pixel in question
            // ** you'll have to modify to account for boundary conditions **
            int row_index = row + row_offset - kernel_rows/2;
            int col_index = col + col_offset - kernel_cols/2;

            int r =0;
            int g =0;
            int b =0;




            r += (data[row_index][col_index].red * kernel[row_offset][col_offset])/16;
            g += (data[row_index][col_index].green * kernel[row_offset][col_offset])/16;
            b += (data[row_index][col_index].blue * kernel[row_offset][col_offset])/16;
            Pixel temp =new Pixel( r, g, b );
            original[row][col] = temp;
          }
        }
        data = original;
        pi.setData(data);

      }
    }
   }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:42:48+00:00Added an answer on June 1, 2026 at 8:42 pm

    A convolution is essentially a quadruple nested loop: two to loop through the pixels in the image and, at each pixel, two to loop over the pixels in the kernel.

    So you can clean up your code significantly with something like this:

       int kernel_rows = 3;
       int kernel_cols = 3;
    
       // define kernel here (double loop), these are the 1/16, 2/16, etc...
       // values that you're multiplying the image pixels by
       double[][] kernel = ... 
    
       // iterate over each pixel in the image
       // leave a kernel_rows/2 sized gap around the edge of the image
       // so that we don't run into IndexOutOfBounds exceptions
       // when performing the convolution
       for (int row = kernel_rows/2; row < pi.getHeight() - kernel_rows/2; row ++) {
         for (int col = kernel_cols/2; col < pi.getWidth() - kernel_cols/2; col++) {
    
           int r = 0;
           int g = 0;
           int b = 0;
    
           // iterate over each pixel in the kernel
           for (int row_offset = 0 ; row_offset < kernel_rows ; row_offset++ ) {
             for (int col_offset = 0 ; col_offset < kernel_cols ; col_offset++ ) {
    
               // subtract by half the kernel size to center the kernel
               // on the pixel in question
               int row_index = row + row_offset - kernel_row/2;
               int col_index = col + col_offset - kernel_cols/2
    
               r += data[row_index][col_index].red * kernel[row_offset][col_offset];
               g += data[row_index][col_index].green * kernel[row_offset][col_offset];
               b += data[row_index][col_index].blue * kernel[row_offset][col_offset];
    
             }
           }
    
         data[row][col] = new Pixel( r, g, b );
    
         }
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi I'm trying create chat using node.js I see example in http://chat.nodejs.org/ I have
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
Ok so I am trying create a login script, here I am using PHP5
Trying to create a background-image slideshow and am getting this error... This is the
Trying to create a PhoneGap app using the canvas tag on an iPad. The
I'm trying create a RCP Application with Eclipse, but I can't get past the
I'm trying create a ASMX webservice that can perform a HTTP GET request. I
All, I am trying create a 'to & fro' animation using jquery animate &
Trying to create the following routine in MySQL Workbench yields a This object's DDL
I'm trying create this function such that if any key besides any of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.