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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:53:08+00:00 2026-05-15T13:53:08+00:00

I have a probably pretty simple question but I am still not sure! Actually

  • 0

I have a probably pretty simple question but I am still not sure!

Actually I only want to smooth a histogram, and I am not sure which of the following to methods is correct. Would I do it like this:

vector<double> mask(3);
mask[0] = 0.25; mask[1] = 0.5; mask[2] = 0.25;

vector<double> tmpVect(histogram->size());
for (unsigned int i = 0; i < histogram->size(); i++)
  tmpVect[i] = (*histogram)[i];

for (int bin = 1; bin < histogram->size()-1; bin++) {
  double smoothedValue = 0;
  for (int i = 0; i < mask.size(); i++) {
    smoothedValue += tmpVect[bin-1+i]*mask[i];
  }
  (*histogram)[bin] = smoothedValue;
}

Or would you usually do it like this?:

vector<double> mask(3);
mask[0] = 0.25; mask[1] = 0.5; mask[2] = 0.25;

for (int bin = 1; bin < histogram->size()-1; bin++) {
  double smoothedValue = 0;
  for (int i = 0; i < mask.size(); i++) {
    smoothedValue += (*histogram)[bin-1+i]*mask[i];
  }
  (*histogram)[bin] = smoothedValue;
}

My Questin is: Is it resonable to copy the histogram in a extra vector first so that when I smooth at bin i I can use the original i-1 value or would I simply do smoothedValue += (*histogram)[bin-1+i]*mask[i];, so that I use the already smoothed i-1 value instead the original one.

Regards & Thanks for a reply.

  • 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-15T13:53:09+00:00Added an answer on May 15, 2026 at 1:53 pm

    Your intuition is right: you need a temporary vector. Otherwise, you will end up using partly old values, and partly new values, and the result will not be correct. Try it yourself on paper with a simple example.

    There are two ways you can write this algorithm:

    1. Copy the data to a temporary vector first; then read from that one, and write to histogram. This is what you did in your first code fragment.
    2. Read from histogram and write to a temporary vector; then copy from the temporary vector back to histogram.

    To prevent needless copying of data, you can use vector::swap. This is an extremely fast operation that swaps the contents of two vectors. Using strategy 2 above, this would result in:

    vector<double> mask(3);
    mask[0] = 0.25; mask[1] = 0.5; mask[2] = 0.25;
    
    vector<double> newHistogram(histogram->size());
    
    for (int bin = 1; bin < histogram->size()-1; bin++) {
      double smoothedValue = 0;
      for (int i = 0; i < mask.size(); i++) {
        smoothedValue += (*histogram)[bin-1+i]*mask[i];
      }
      newHistogram[bin] = smoothedValue;
    }
    
    histogram->swap(newHistogram);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a input tag which is non editable, but some times i need
I know its probably possible, but is it practical and doable to try and
I know its probably possible, but is it practical and doable to try and
I have a login.jsp page which contains a login form. Once logged in the
I have a project that adds elements to an AutoCad drawing. I noticed that
I have a script that appends some rows to a table. One of the
I have a new web app that is packaged as a WAR as part
I have several USB mass storage flash drives connected to a Ubuntu Linux computer
I have a snippet to create a 'Like' button for our news site: <iframe
I have found this example on StackOverflow: var people = new List<Person> { new

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.