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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:47:50+00:00 2026-06-09T03:47:50+00:00

im tryn to add a new adaptive threshold method to the AForge.Imaging.Filters I have

  • 0

im tryn to add a new adaptive threshold method to the AForge.Imaging.Filters

I have added the new cs file under

Sources\Imaging\Filters\Adaptive Binarization

Below is the code for the thresholding methods

namespace AForge.Imaging.Filters
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Drawing.Imaging;
    using AForge.Imaging;

    class SauvolaAdaptiveThresholding : BaseInPlacePartialFilter
    {
        private const float DEFAULT_WeightingFactor = 0.3f;
        private const short DEFAULT_WindowSize = 40;

        private float weightingFactor ;
        private short windowSize ;
        // private format translation dictionary
        private Dictionary<PixelFormat, PixelFormat> formatTranslations = new Dictionary<PixelFormat, PixelFormat>();

        /// <summary>
        /// Format translations dictionary.
        /// </summary>
        public override Dictionary<PixelFormat,PixelFormat>  FormatTranslations
        {
            get { return formatTranslations; }
        }
        public float WeightingFactor
        {
            get{return this.weightingFactor;}
            set{this.weightingFactor = value;}
        }
        public short WindowSize
        {
            get{return this.windowSize;}
            set{this.windowSize = value;}
        }
        public SauvolaAdaptiveThresholding() :
            this(DEFAULT_WeightingFactor,DEFAULT_WindowSize)   {  }

        public SauvolaAdaptiveThresholding(float _weightFact , short _wsize)
        {
            this.WeightingFactor = _weightFact;
            this.WindowSize =_wsize;
            // initialize format translation dictionary
            formatTranslations[PixelFormat.Format8bppIndexed] = PixelFormat.Format8bppIndexed;
            formatTranslations[PixelFormat.Format16bppGrayScale] = PixelFormat.Format16bppGrayScale;
        }
        protected override unsafe void ProcessFilter(UnmanagedImage image, Rectangle rect)
        {
            int whalf = windowSize >> 1; //half of windowsize
            whalf = windowSize >> 1;

            byte* ptr = (byte*)image.ImageData.ToPointer(); //input         

            // Calculate the integral image, and integral of the squared image
            ulong[,] integral_image = new ulong[image.Width , image.Height];
            ulong[,] rowsum_image = new ulong[image.Width , image.Height];
            ulong[,] integral_sqimg = new ulong[image.Width , image.Height];
            ulong[,] rowsum_sqimg = new ulong[image.Width , image.Height];

            int xmin, ymin, xmax, ymax, index;
            double diagsum, idiagsum, diff, sqdiagsum, sqidiagsum, sqdiff, area;
            double mean, std, threshold;

            for (int j = 0; j < image.Height; j++)
            {
                rowsum_image[0, j] = (ulong)*(ptr + j);
                rowsum_sqimg[0, j] = rowsum_image[0, j] * rowsum_image[0, j];
            }
            for (int i = 1; i < image.Width; i++)
            {
                for (int j = 0; j < image.Height; j++)
                {
                    index = j * image.Width + i;
                    rowsum_image[i, j] = rowsum_image[i - 1, j] + (ulong)*(ptr + index);
                    rowsum_sqimg[i, j] = rowsum_sqimg[i - 1, j] + (ulong)(*(ptr + index) * *(ptr + index));
                }
            }

            for (int i = 0; i < image.Width; i++)
            {
                integral_image[i, 0] = rowsum_image[i, 0];
                integral_sqimg[i, 0] = rowsum_sqimg[i, 0];
            }
            for (int i = 0; i < image.Width; i++)
            {
                for (int j = 1; j < image.Height; j++)
                {
                    integral_image[i, j] = integral_image[i, j - 1] + rowsum_image[i, j];
                    integral_sqimg[i, j] = integral_sqimg[i, j - 1] + rowsum_sqimg[i, j];
                }
            }
            //Calculate the mean and standard deviation using the integral image
            for (int i = 0; i < image.Width; i++)
            {
                for (int j = 0; j < image.Height; j++)
                {
                    xmin = Math.Max(0, i - whalf);//max(0, i - whalf);
                    ymin = Math.Max(0, j - whalf);
                    xmax = Math.Min(image.Width - 1, i + whalf);
                    ymax = Math.Min(image.Height - 1, j + whalf);
                    area = (xmax - xmin + 1) * (ymax - ymin + 1);

                    if (xmin == 0 && ymin == 0)
                    { // Point at origin
                        diff = integral_image[xmax, ymax];
                        sqdiff = integral_sqimg[xmax, ymax];
                    }
                    else if (xmin == 0 && ymin != 0)
                    { // first column
                        diff = integral_image[xmax, ymax] - integral_image[xmax, ymin - 1];
                        sqdiff = integral_sqimg[xmax, ymax] - integral_sqimg[xmax, ymin - 1];
                    }
                    else if (xmin != 0 && ymin == 0)
                    { // first row
                        diff = integral_image[xmax, ymax] - integral_image[xmin - 1, ymax];
                        sqdiff = integral_sqimg[xmax, ymax] - integral_sqimg[xmin - 1, ymax];
                    }
                    else
                    { // rest of the image
                        diagsum = integral_image[xmax, ymax] + integral_image[xmin - 1, ymin - 1];
                        idiagsum = integral_image[xmax, ymin - 1] + integral_image[xmin - 1, ymax];
                        diff = diagsum - idiagsum;
                        sqdiagsum = integral_sqimg[xmax, ymax] + integral_sqimg[xmin - 1, ymin - 1];
                        sqidiagsum = integral_sqimg[xmax, ymin - 1] + integral_sqimg[xmin - 1, ymax];
                        sqdiff = sqdiagsum - sqidiagsum;
                    }

                    mean = diff / area;
                    std = Math.Sqrt((sqdiff - diff * diff / area) / (area - 1));
                    threshold = mean * (1 + WeightingFactor * ((std / 128) - 1));
                    if ((double)*(ptr + (j * image.Width + i)) < threshold)//if (gray_image[i, j] < threshold)
                        *(ptr + (j * image.Width + i)) = 0;
                    else
                        *(ptr + (j * image.Width + i)) = 255;
                }
            }
          }
        }
}

but when i build the project and use the AForge.Imaging.dll, the above class isn’t available. When i try to use the object browser i see all the other classes except for the one i added newly.

Can someone please tell me what am i doing wrong?

  • 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-09T03:47:52+00:00Added an answer on June 9, 2026 at 3:47 am

    It needs to be public

    public class SauvolaAdaptiveThresholding : BaseInPlacePartialFilter
    

    You can find more info about the C# access modifiers here: http://msdn.microsoft.com/en-us/library/ms173121.aspx

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

Sidebar

Related Questions

In the following program abort method is called even when I have got the
I have this code: FILE *f = fopen(intPath, r); Node *n; if (f) {
I have a tool, similar in ways to JSFiddle, that allows me to dynamically
I have a function in which I call getaddrinfo() to get an sockaddr* which
As a toy example, suppose that we have a function called 'my_func' (the code
I have a graph in Neo4j in which nodes represent random points in the
I'm tryn to get the username and password by email address and send it
I have a problem, I have this pointers in my thread code and they
I have some doubts about optimistic concurrency exception. Well, For example, I retrieve some
I am trying to implement a linked list using following code, I got segment

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.