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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:11:24+00:00 2026-05-27T23:11:24+00:00

in this function i have a matrix of colors(each pixel can has a value

  • 0

in this function i have a matrix of colors(each pixel can has a value from 0 to 9) and what i want to do is to reduce noise. pixels that have, more than 5 neighbor, with the same color are changed to that color! i define an array[0-9] to hold the number of neighbors color for example if 6 pixel has the value of 8 and 2 has the value of 5 the array should be like this [0,0,0,0,0,2,0,6,0,0] but when i print the array the value of first element( array[0]) is wrong ,it starts with 8 and each time pulse by 8 ! here is the code.
can you help me pls ?

::Error image link::

void Noise_Reduction(CvMat* Color_mat,boolean showresult){
int tv[__COLORNUM]={0,0,0,0,0,0,0,0,0};
int counter;

for(int y=1;y<Color_mat->height-1;y++)
{
    for(int x=1;x<Color_mat->width-1;x++)
    {   
        for(int i=0;i<9;i++,tv[i]=0);           
        tv[CV_MAT_ELEM(*Color_mat,uchar,y-1,x-1)]++;
        tv[CV_MAT_ELEM(*Color_mat,uchar,y-1,x  )]++;
        tv[CV_MAT_ELEM(*Color_mat,uchar,y-1,x+1)]++;
        tv[CV_MAT_ELEM(*Color_mat,uchar,y  ,x-1)]++;
        tv[CV_MAT_ELEM(*Color_mat,uchar,y  ,x+1)]++;
        tv[CV_MAT_ELEM(*Color_mat,uchar,y+1,x-1)]++;
        tv[CV_MAT_ELEM(*Color_mat,uchar,y+1,x  )]++;
        tv[CV_MAT_ELEM(*Color_mat,uchar,y+1,x+1)]++;
        for(int i=0;i<9;i++){
        std::cout<<tv[i]<<",";}
        std::cout<<endl;
        int max=0;
        int indx=0; 
        max= tv[0];
        for(int i = 1; i<__COLORNUM; i++)
         {
             if(tv[i] > max){
                    max = tv[i];
                    indx=i;
             }

         }

        if(max>=5)
        {
            counter++;
            *( (uchar*)CV_MAT_ELEM_PTR( *Color_mat, y, x ))=(uchar)indx;
            //std::cout<<"times:"<<counter <<endl;

        }

    }
}
std::cout<<"times:"<<counter <<endl;    

if(showresult){
    IplImage* Noise_result = cvCreateImage(cvSize(Color_mat->width,Color_mat->height),IPL_DEPTH_8U,3);
    for( int y=0; y<Noise_result->height; y++ ) {
        uchar* ptr = (uchar*)(Color_mat->data.ptr + y * Color_mat->step);
        for( int x=0; x<Noise_result->width; x++ ) {
            switch ( *ptr) {

                          case 1 : 
                              cvSet2D(Noise_result,y,x,oo);
                              break;

                          case 2 : 
                              cvSet2D(Noise_result,y,x,bb);
                              break;

                          case 3 : 
                              cvSet2D(Noise_result,y,x,yy);
                              break;

                          case 4 : 
                              cvSet2D(Noise_result,y,x,gg);
                              break;

                          case 5 : 
                              cvSet2D(Noise_result,y,x,ww);
                              break;

                          default :  
                              cvSet2D(Noise_result,y,x,uk);
                              break;
            }
            ptr++;
        }
    }

    if(showresult)
{
    cvNamedWindow( "Noiseresult", CV_WINDOW_FREERATIO);
    cvShowImage( "Noise_result", Noise_result );
    cvWaitKey(0);

}



}

}

  • 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-05-27T23:11:25+00:00Added an answer on May 27, 2026 at 11:11 pm
    for(int i=0;i<9;i++,tv[i]=0);
    

    That line looks fishy (it will never set tv[0] to 0), don’t you mean this instead:

    for(int i=0;i<9;tv[i]=0,i++);
    

    (Or even better: memset(tv, 0, sizeof(tv));)

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

Sidebar

Related Questions

I have a simple function about neural network. This function gets a matrix, loads
I have a function like this: MyFunction(double matrix[4][4]) {/*do stuff*/} I am calling this
I have a function that returns a comparison matrix from a given list: def
I have a matrix: Array2D and a function let DivideAndSubstract value index (matrix: float[,])
I have a function compute() that has parallelized matrix multiplication inside of it using
I have function like this: function gi_insert() { if(!IS_AJAX){ $this->load->library('form_validation'); $this->form_validation->set_rules('name', 'Naslov', 'trim|required|strip_tags'); $this->form_validation->set_rules('body',
Suppose I have this function, in pseudo-code, that reverse a list: def function reverse(
Suppose I have this function: void my_test() { A a1 = A_factory_func(); A a2(A_factory_func());
So I have this function that forks N number of child processes. However it
So I have this function: (define (try try-block catch-block finally-block) ; Implements try/catch/finally like

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.