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

  • Home
  • SEARCH
  • 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 8254355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:09:43+00:00 2026-06-08T01:09:43+00:00

I have an image that I’m trying to blur out, but it ends up

  • 0

I have an image that I’m trying to blur out, but it ends up looking very weird indeed:

enter image description here

What I DO is this: I take each pixel, and I average its value on a color-by-color basis with the values of all adjacent pixels.

Or so I think. But there’s clearly an error in there, and I suspect there’s a problem with my for-loops but for the life of me I cannot find out what is actually going wrong.

In particular, step five (the output step) shows that the image is still ordered – if I output the left image on the right side, rather than the blur-masked image, the pixels are still in the correct order.

    try
{
    // STEP ONE: MAKE MEMORY AVAILABLE FOR IMAGE
    int ***image;
    image = new int**[m_nSizeX];
    for(int i = 0; i < m_nSizeX; ++i)
    {
        image[i] = new int*[m_nSizeY];
        for(int j = 0; j < m_nSizeY; ++j)
        {
            image[i][j] = new int[nrPixels];// image[x][y][z] is now a pointer to an int

        }
    }

    // STEP TWO: MAKE MEMORY AVAILABLE FOR IMAGE MASK
    int ***mask;
    mask = new int**[m_nSizeX];
    for(int i = 0; i < m_nSizeX; ++i)
    {
        mask[i] = new int*[m_nSizeY];
        for(int j = 0; j < m_nSizeY; ++j)
        {
            mask[i][j] = new int[nrPixels];// mask[x][y][z] is now a pointer to an int

        }
    }

    //STEP THREE: COPY IMAGE INTO MEMORY

    unsigned long lOffset = 0;
    for(long i=0; i<m_nSizeX ; i++)
    {
        for(long j=0; j<m_nSizeY ; j++)
        {
            for(int k=0; k<(nrPixels) ; k++)
            {
                image[i][j][k] = *(reinterpret_cast<unsigned char*>(m_pcMemOrg + lOffset) );
                lOffset++;
            }
        }
    }

    // STEP FOUR: BLUR IMAGE

    for(long i=0; i<m_nSizeX ; i++)
    {
        for(long j=0; j<m_nSizeY ; j++)
        {
            for(int k=0; k<(nrPixels) ; k++)
            {
                // INSERT BLURRING FUNCTION HERE (New value = Old value averaged with adjacent pixels)

                if(k != 2) // 0 = blue, 1 = green, 2 = red;
                {
                    mask[i][j][k] = 0;
                }
                else


                if(i==0 && j==0)// (0,0) Corner Pixel
                {
                    mask[i][j][k] = (image[i][j][k]+image[i+1][j][k]+image[i][j+1][k]+image[i+1][j+1][k])/4;
                }
                else if(i==0 && j==(m_nSizeY-1))// (0,yMax) Corner Pixel
                {
                    mask[i][j][k] = (image[i][j][k]+image[i+1][j][k]+image[i][j-1][k]+image[i+1][j-1][k])/4;
                }
                else if(i==(m_nSizeX-1) && j==0)// (xMax,0) Corner Pixel
                {
                    mask[i][j][k] = (image[i][j][k]+image[i-1][j][k]+image[i][j+1][k]+image[i-1][j+1][k])/4;
                }
                else if(i==(m_nSizeX-1) && j==(m_nSizeY-1))// (xMax,yMax) Corner Pixel
                {
                    mask[i][j][k] = (image[i][j][k]+image[i-1][j][k]+image[i][j-1][k]+image[i-1][j-1][k])/4;
                }
                else if(i==0)// (0,---) Edge Pixels
                {
                    mask[i][j][k] = (image[i][j][k]+image[i][j+1][k]+image[i+1][j+1][k]+image[i+1][j][k]+image[i+1][j-1][k]+image[i][j-1][k])/6;
                }
                else if(j==0)// (---,0) Edge Pixels
                {
                    mask[i][j][k] = (image[i][j][k]+image[i-1][j][k]+image[i-1][j+1][k]+image[i][j+1][k]+image[i+1][j+1][k]+image[i+1][j][k])/6;                    
                }
                else if(i==(m_nSizeX-1))// (xMax,---) Edge Pixels
                {
                    mask[i][j][k] = (image[i][j][k]+image[i][j-1][k]+image[i-1][j-1][k]+image[i-1][j][k]+image[i-1][j+1][k]+image[i][j+1][k])/6;
                }
                else if(j==(m_nSizeY-1))// (---,yMax) Edge Pixels
                {
                    mask[i][j][k] = (image[i][j][k]+image[i+1][j][k]+image[i+1][j-1][k]+image[i][j-1][k]+image[i-1][j-1][k]+image[i-1][j][k])/6;
                }
                else // Mid-Image Pixels
                {
                    mask[i][j][k] = (image[i][j][k]+image[i][j+1][k]+image[i+1][j+1][k]+image[i+1][j][k]+image[i+1][j-1][k]+image[i][j-1][k]+image[i-1][j-1][k]+image[i-1][j][k]+image[i-1][j+1][k])/9;
                }
            }
        }
    }

    //STEP FIVE: OUTPUT BLURRED IMAGE
    lOffset = 0;

    for(long i=0; i<m_nSizeX ; i++)
    {
        for(long j=0; j<m_nSizeY ; j++)
        {
            for(int k=0; k<(nrPixels) ; k++)
            {
                *(reinterpret_cast<unsigned char*>(m_pcMemInv + lOffset) ) = mask[i][j][k];
                //*(reinterpret_cast<unsigned char*>(m_pcMemInv + lOffset) ) = image[i][j][k];
                lOffset++;
            }
        }
    }


    // STOP USING IMAGE MEMORY NOW

    for (int i = 0; i < m_nSizeX; ++i) {
        for (int j = 0; j < m_nSizeY; ++j)
            delete [] image[i][j];

        delete [] image[i];
    }
    delete [] image;

    // STOP USING MASK MEMORY NOW
    for (int i = 0; i < m_nSizeX; ++i) {
        for (int j = 0; j < m_nSizeY; ++j)
            delete [] mask[i][j];

        delete [] mask[i];
    }
    delete [] mask;
}
catch( ... )
{

}
  • 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-08T01:09:44+00:00Added an answer on June 8, 2026 at 1:09 am

    When using multi-dimensional indexing, usually the first index is y, the second x and the third red/green/blue – you use a nonstandard transposed layout with i, j and k, where i seems to mean a horizontal index (seeing that you compare it to m_nSizeX).

    I guess your image is getting transposed when you copy it the first time, transformed in a mysterious way, and transposed back when you copy it the second time; i cannot guess the details, but it’s enough to advise you to just get the dimensions right (swap i and j).

    By the way, calling coordinates the normal names x and y (instead of i and j, or maybe j and i?) helps.

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

Sidebar

Related Questions

I have image map that can I move, but this map will be so
I have an image that is served as static file using Nginx, but I
I have an image that, depending on the screen resolution, drops down out of
I have an image that is pretty large in size, and I am trying
I have image that needs to be scrolled in uiscrollview but scrolling needs to
I have an image that I'm trying to load in IE9. I can get
I have an image that returns everytime the user scrolls the uitableview. This code
I want to have an image that would initially be black and white, but
I have an image that is generated automatically inside an Ajax UpdatePanel. This image
I have this image that comes back from an API, which represents the users

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.