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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:10:09+00:00 2026-05-13T07:10:09+00:00

Firstly apologies for the title, I don’t know if it describes what I am

  • 0

Firstly apologies for the title, I don’t know if it describes what I am trying to achieve but its the best I’ve got.

Basically I have an array describing the intensity over a 2D space. I want to then distribute this intensity to neighbors over a given set of iterations, i.e. Lets say I have the following array:

intensity = [ 0, 0, 0, 0, 0, 
              0, 0, 0, 0, 0, 
              0, 0, 0, 0, 0, 
              0, 0, 100, 0, 0, 
              0, 0, 0, 0, 0, 
              0, 0, 0, 0, 0,
              0, 0, 0, 0, 0 ]

I then do one pass over my distributeIntensity algorithm (distributing 50% of intensity to neighbours). I then would have:

            [ 0,  0,   0,  0, 0, 
              0,  0,   0,  0, 0, 
              0, 50,  50, 50, 0, 
              0, 50, 100, 50, 0, 
              0, 50,  50, 50, 0, 
              0,  0,   0,  0, 0,
              0,  0,   0,  0, 0 ]

If I do 2 passes over the original array my resulting array would be:

          [ 0,   0,   0,   0, 0, 
           25,  50,  75,  50, 25, 
           50, 150, 200, 150, 50, 
          75, 200, 300, 200, 75, 
           50, 150, 200, 150, 50, 
           25,  50,  75,  50, 25,
            0,   0,   0,   0, 0 ]

My current code is:

this.distributeIntensities = function(passes, shareRatio) {     
    for (var i = 0; i < passes; i++) { this.distributeIntensity(shareRatio); }
}

this.distributeIntensity = function(shareRatio) {       
    var tmp = hm.intensity.slice(0); // copy array
    for (var i = 0; i < tmp.length; i++) {          
        if (hm.intensity[i] <= 0) { continue; }
        var current = hm.intensity[i];
        var shareAmount = current * shareRatio;                     
        this.shareIntensityWithNeighbours(tmp, shareAmount, i);                                                             
    }       
    hm.intensity = tmp;
}

this.shareIntensityWithNeighbours = function(arr, heat, i) {                    
    // This should be var x = Math.floor(...) however 
    // this is slower and without gives satisfactory results
    var x = i % hm.columnCount; 
    var y = i / hm.columnCount; 

    if (x > 0) {
        if (y > 0) arr[i - hm.columnCount - 1] += heat;
        arr[i - 1] += heat;
        if (y < (hm.rowCount - 1)) arr[i + hm.columnCount - 1] += heat;
    }               

    if (y > 0) arr[i - hm.columnCount] += heat;     
    if (y < (hm.rowCount - 1)) arr[i + hm.columnCount] += heat;

    if (x < (hm.columnCount - 1)) {
        if (y > 0) arr[i - hm.columnCount + 1] += heat;
        arr[i + 1] += heat;
        if (y < (hm.rowCount - 1)) arr[i + hm.columnCount + 1] += heat;
    }               
}

Now, this works however it is very slow (I am working with a huge array and 8 passes). I know there is a faster/better/cleaner way of doing this but it is beyond my abilities so I put it out there in the hope that someone can point me in the right direction (Note: I do not speak fluent mathematics, in fact I’m pretty mathematically illiterate).

Thanks in advance

Guido

  • 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-13T07:10:10+00:00Added an answer on May 13, 2026 at 7:10 am

    Convolution is a common image manipulation technique (now you have a keyword to search for!).

    [[ 0.5, 0.5, 0.5 ],
     [ 0.5, 1.0, 0.5 ],
     [ 0.5, 0.5, 0.5 ]]
    

    It looks like you’ve implemented convolution with this kernel, manually.

    To speed things up: because convolution is associative, you can pre-compute a single filter, instead of applying the original multiple times. For example, if passes = 2,

    once = [[ 0.5, 0.5, 0.5 ], [ 0.5, 1.0, 0.5 ], [ 0.5, 0.5, 0.5 ]]
    twice = once ⊗ once =
        [[ 0.25, 0.50, 0.75, 0.50, 0.25 ],
         [ 0.50, 1.50, 2.00, 1.50, 0.50 ],
         [ 0.75, 2.00, 3.00, 2.00, 0.75 ], 
         [ 0.50, 1.50, 2.00, 1.50, 0.50 ], 
         [ 0.25, 0.50, 0.75, 0.50, 0.25 ]]
    
    distribute(hm) = hm ⊗ once ⊗ once
                   = hm ⊗ twice
    

    If you will be doing this repeatedly, it may be worthwhile to learn the Fourier Transform; there is a theorem stating that

    FT(X ⊗ Y) = FT(X) ⋅ FT(Y)
    

    or after applying the Inverse Fourier Transform,

    X ⊗ Y = IFT(FT(X) ⋅ FT(Y))
    

    In other words, complicated convolutions can be replaced by simple multiplications.

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

Sidebar

Related Questions

Firstly, apologies for the vague title, but I'm not sure exactly what I'm asking
Firstly, apologies for the bad question title - not entirely sure if I am
Firstly, let me set out what I'd like to do. Assume I have three
So firstly here's my query: ( NOTE:I know SELECT * is bad practice I
Firstly, bear with me here. I have a custom model binder which is successfully
I have a modeling question related to profiles. Firstly, I have looked into using
Firstly, I'm a newbie to C# and SharePoint, (less than a month's experience) so
Firstly, Real World Haskell , which I am reading, says to never use foldl
I wish to order a table: Firstly by Field1=3 Then by Field2 DESC I
I have a WPF sorting/binding issue. (Disclaimer: I am very new to WPF and

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.