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 8646699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:52:53+00:00 2026-06-12T12:52:53+00:00

I’m trying to make a simple blur effect in c. I have an image

  • 0

I’m trying to make a simple blur effect in c. I have an image loaded in an 512*512 array of RGB pixels and I’m using 3×3 kernel to blur that image

here is the kernel

float matrix[9] = {1.0f/9.0f, 1.0f/9.0f, 1.0f/9.0f, 1.0f/9.0f, 1.0f/9.0f, 1.0f/9.0f, 1.0f/9.0f, 1.0f/9.0f, 1.0f/9.0f};

and here is the code that is doing the bluring

void useBlur(){

  for(int i = 0; i < ARRAY_SIZE; i++){
      float r = 0;
      float g = 0;
      float b = 0;
      int m, n;

      for(int y = -1,  m = 0; y <= 1; y++, m++){
          for(int z = -1,  n = 0; z <= 1; z++, n++){
              r += (float)orig_image[i + 512 * y + z].r * (float)matrix[m*3+n];
              g += (float)orig_image[i + 512 * y + z].g * (float)matrix[m*3+n];
              b += (float)orig_image[i + 512 * y + z].b * (float)matrix[m*3+n];
          }

      }

      image[i].r = r;
      image[i].g = g;
      image[i].b = b;

  }
}

I’m not sure what is wrong with that code, but it is producing result:

enter image description here

Any ideas why the colors are wrong? And how to fix it?

EDIT:
fixed matrix[7] from 9.0/9.0 to 1.0/9.0 and uploaded new image

  • 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-12T12:52:55+00:00Added an answer on June 12, 2026 at 12:52 pm

    I tried your code with some changes, the images I have are BGRA and I am using opencv for my image container but the structure of the code is the same and it works perfectly.

        for (int i = 2*image.cols; i < image.rows*image.cols-2*image.cols; i++)
        {
            float r = 0;
            float g = 0;
            float b = 0;
    
            for (int y = -1; y <=1; y++)
            {
                for (int z = -1; z <=1; z++)
                {
                    b += (float)image.at<cv::Vec4b>(i + image.cols*y+z)(0)*(1.0/9);
                    g += (float)image.at<cv::Vec4b>(i + image.cols*y+z)(1)*(1.0/9);
                    r += (float)image.at<cv::Vec4b>(i + image.cols*y+z)(2)*(1.0/9);
                }
            }
            image.at<cv::Vec4b>(i)(0) = b;
            image.at<cv::Vec4b>(i)(1) = g;
            image.at<cv::Vec4b>(i)(2) = r;
        }
    

    I would assume that means the problem is either not in the code you posted, or somehow the opencv cv::Mat class is handling something your image container is not. The obvious candidate for that would be that you seem to be implicitly converting from float to uchar at the end of your code. Could you test running this loop over your image but without modifying it? It could look like this, or any number of other ways. This is ugly, but a quick conversion.

    void useBlur(){
    
    for(int i = 0; i < ARRAY_SIZE; i++){
      float r = 0;
      float g = 0;
      float b = 0;
      int m, n;
    
      for(int y = -1,  m = 0; y <= 1; y++, m++){
          for(int z = -1,  n = 0; z <= 1; z++, n++){
              if(y == 0 && z == 0)
              {
                r += (float)orig_image[i + 512 * y + z].r * (float)matrix[m*3+n]*9;
                g += (float)orig_image[i + 512 * y + z].g * (float)matrix[m*3+n]*9;
                b += (float)orig_image[i + 512 * y + z].b * (float)matrix[m*3+n]*9;
              }
          }
    
      }
    
      image[i].r = r;
      image[i].g = g;
      image[i].b = b;
    
     }
     }
    

    Theoretically nothing should change about the image when you do that, so if the image is changing it is because of some conversion error. I admit the theory is unlikely but the structure of your code seems sound so I don’t know what else to suggest.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have an array which has BIG numbers and small numbers in it. I
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.