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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:47:38+00:00 2026-06-17T07:47:38+00:00

I am doing an image processing assignment where I want to implement erosion and

  • 0

I am doing an image processing assignment where I want to implement erosion and dilation algorithm. It needs to look for each pixel in all directions (in this case up, down, left and right), so i’m using a plus structuring element. Here is my problem: I’ve got 4 for loops nested, which makes this operation very slow.
Can anyone tell me how to make the erosion process quicker without using unsafe method?
Here is what I have:

        colorlistErosion = new List<Color>();
        int colorValueR, colorValueG, colorValueB;
        int tel = 0;

        for (int y = 0; y < bitmap.Height; y++)
        {
            for (int x = 0; x < bitmap.Width; x++)
            {
                Color col = bitmap.GetPixel(x, y);
                colorValueR = col.R; colorValueG = col.G; colorValueB = col.B;
                //Erosion
                for (int a = -1; a < 2; a++)
                {
                    for (int b = -1; b < 2; b++)
                    {
                        try
                        {
                            Color col2 = bitmap.GetPixel(x + a, y + b);
                            colorValueR = Math.Min(colorValueR, col2.R);
                            colorValueG = Math.Min(colorValueG, col2.G);
                            colorValueB = Math.Min(colorValueB, col2.B);
                        }
                        catch
                        {
                        }
                    }
                }
                colorlistErosion.Add(Color.FromArgb(0 + colorValueR, 0+colorValueG, 0+colorValueB));
            }
        }
        for (int een = 0; een < bitmap.Height; een++)
            for (int twee = 0; twee < bitmap.Width; twee++)
            {
                bitmap.SetPixel(twee, een, colorlistErosion[tel]);
                tel++;
            }
  • 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-17T07:47:39+00:00Added an answer on June 17, 2026 at 7:47 am

    how to make the erosion process quicker without using unsafe method?

    You can turn the inner loops into Parallel.For().

    But I’m not 100% sure if GetPixel() and especially SetPixel() are thread-safe. That is a deal-breaker.

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

Sidebar

Related Questions

I'm doing some image processing, and I'd like to individually read each pixel value
I'm doing image processing with ImageMagick commands and I would like to port them
I'm currently trying to teach myself PHP by doing a small image-processing type project
I'm doing a project that use image processing techniques to identify different objects and
I am doing a lot of image processing in GDI+ in .NET in an
I'm doing a research project on Image processing. The project is to Evaluate users
I am doing image Read/Copy operations in WPF application. Please look at following piece
I am doing a lot of image processing in C and I need a
I want to write a graphics library for image processing and computer vision. Because
I am doing image processing in C that requires copying large chunks of data

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.