Tips for Enhancing Window Leveling (Brightness and Contrast)

  const pixelArray = [11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11..]  
    if (pixelArray != null)
            {
                for (let i = 0; i < pixelArray.length; i++)
                {
                    let pixel = pixelArray[i];
                    pixel = applyWindowLevel(pixel, imageWC, imageWW);
                    pixel = lutArray[pixel];

                    // let red = (pixel & 0x00ff0000) >> 16;
                    let v = i * 4;
                    imageData[v] = pixel & 0xff;
                    imageData[v + 1] = (pixel >>> 8) & 0xff;
                    imageData[v + 2] = (pixel >>> 16) & 0xff;
                    imageData[v + 3] = 255;
                }
                // offscreenCtx.imageSmoothingEnabled = true;
                offscreenCtx.putImageData(g, 0, 0);
            }
function applyWindowLevel(value, windowCenter, windowWidth)
        {
            recalculate(windowCenter, windowWidth);
            if (value <= windowStart)
                value = minimumOutputValue;
            else if (value > windowEnd)
                value = maximumOutputValue;
            else
            {
                value = Math.round((((value - windowCenterMin05) / windowWidthMin1) + 0.5) * 255.0);
            }
            return value;
        }

        var minimumOutputValue = 0;
        var maximumOutputValue = 255;
        function recalculate(windowCenter, windowWidth)
        {
            if (!valid)
            {
                windowCenterMin05 = windowCenter - 0.5;
                windowWidthMin1 = windowWidth - 1;
                windowWidthDiv2 = windowWidthMin1 / 2;
                windowStart = (windowCenterMin05 - windowWidthDiv2);
                windowEnd = (windowCenterMin05 + windowWidthDiv2);
                valid = true;
            }
        }


Width: <input id="text1" type="text" />
    Center: <input id="text2" type="text" />
    <input id="Button1" type="button" value="Apply" onclick="applyCustomWLCust();" /></br>
    Time Required: <input id="text3" type="text" />
    <canvas style="height: 500px; width: 500px; display1: none; background-color: black;
                border: 1px solid red;" id="offscreenCanvas"></canvas>

I have applied window leveling on a Canvas medical image (CR). I receive a pixel array from a C# Component. When the button is clicked, I call the function applyCustomWLCust(); All processes are executed in this function and yield perfect results. For window leveling, bit shifting is used which takes around 585ms. I need to reduce this processing time; any suggestions or solutions would be greatly appreciated.

Answer №1

One strategy to optimize performance is to use parallel execution, which can potentially cut down on the time it takes to complete tasks.

You may want to explore this library for implementing parallel execution:


If you are working with a large array, consider dividing it into segments and assigning each segment to a separate parallel execution process with a specified range of indices to process.

  • ParallelExecution1 will handle elements from 0 to 100
  • ParallelExecution2 will handle elements from 101 to 200
  • ParallelExecution3 will handle elements from 201 to 300
  • ...

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unable to insert a JSON object into an Array

This might appear to be a duplicate, but it's not. None of the solutions I've tried have worked. Within my angular module, I have a list: this.checkedInterviews = [] Followed by a function that does the following: var interviewModel = { ...

What is the method for determining the mean of a given set of numbers?

Upon parsing data from the server, here is a snippet of the JSON: { "main": [ { "id": "12345" } ], "parameter": [ { "temp": "30.00", "acc": "3.00", "moisture": "200.00", ...

retrieving request headers using XMLHttpRequest

Is there a way for me to access my requestHeaders within the onload function? Any guidance on how to achieve this would be greatly appreciated. Many thanks! ...

Is it possible to integrate the Firestore npm library into my Express application?

Recently, I created my own library to act as a nosql database on my node.js web server in place of mongodb. I came across this interesting quote: Applications that use Google's Server SDKs should not be used in end-user environments, such as on pho ...

Adding the most recent version of jquery causes the webpage to malfunction

Currently, I am facing a challenge on a website that has an outdated version of jQuery (1.7.2) included in the header. In order to use a plugin that requires the latest version of jQuery, I tried linking the newer version (2.1.3) in the footer. However, j ...

There was a problem finding the correct address indicated by the marker

I am working on an Android app using PhoneGap, and I need to display a marker on a Google map at a specific latitude and longitude. When the marker is clicked, I want to show an info window displaying the address associated with that location. However, t ...

Determine if the value is present in every element of the array and return true

I am looking for a way to determine if all products have the status "Done" in their respective statusLog arrays. If any product does not contain "Done" or lacks the statusLog property altogether, then the function should return false. Although the current ...

Login should only be tried when the error code is 403

I have encountered an issue with checking if the API token is expired. The process involves making a GET call, and if a 403 error is received from the API, then re-login is required. This is what I tried: app.get = async (body) => { return new Pro ...

Tips for loading a webpage based on the selected value of a JQuery dropdown list

I'm currently working on an ASPX webpage where I am developing a feature to create reports using filter criteria. To populate my dropdown list, I am using a jqxwidget which retrieves values from a variable I have defined: var sourceRptType = [ ...

What could be causing input to be blocked in certain situations while using my Angular directive with compile function?

Recently, I created a directive that adds a class based on a certain condition. You can find the code snippet at the end of this question. The directive functions as expected in a simple use case where it's applied to a required field: <input typ ...

When a URL is triggered via a browser notification in Angular 2, the target component ceases to function properly

Whenever I access a URL by clicking on a browser notification, the functionality of the page seems to stop working. To demonstrate this issue, I have a small project available here: https://github.com/bdwbdv/quickstart Expected behavior: after starting t ...

Is it possible to use different names for the parameters in a function while still maintaining the same

(Apologies for any language barriers!) It's difficult to articulate my thoughts in English, but here is the code I've written: function calculateAge(yearBorn){ return 2020 - yearBorn; } var johnAge = calculateAge(1990); var janeAge = calcul ...

utilizing numerous conditional renderings within a mapping function

Hello there, I'm curious if there is a more efficient method to display my todos. Currently, my code looks like this: { todos.map((todo) => ( todo.status === 1 && ( ...

AngularJS testing typically involves the use of the inject module injection process

Currently, I am working on testing a service called documentViewer, which relies on another service named authService. angular .module('someModule') .service('documentViewer', DocumentViewer); /* @ngInject */ function Do ...

Refreshing appsettings.json with Strong Types

This is the content of my appsettings.json file: { "MySettings": { "DefaultSetting": "Key1", "Settings": { "Key1": { "Full": "Description1", "Short&q ...

Override existing Keywords (change false to true)

Are there any ways to overwrite reserved words? It's not something I would typically consider, but it has sparked my curiosity. Is it feasible to set false = true in JavaScript? I've come across instances on different websites where individuals ...

What is the best way to create a slideshow using an IFrame?

Currently seeking a solution for an iframe slideshow that can smoothly transition between multiple HTML iframes. I have a total of 5 iframes that need to rotate automatically and continuously. Any suggestions on how to build a lively and dynamic iframe sl ...

Enhancing functionality in Javascript by employing prototype descriptor for adding methods

Code: Sorter.prototype.init_bubblesort = function(){ console.log(this.rect_array); this.end = this.rect_array.length; this.bubblesort(); } Sorter.prototype.init = function(array,sort_type){ this.rect_array = array; this.init_bubblesort(); } Wh ...

Access data from previous request and transmit it to another request in a Node.js environment

I am facing a situation where I need to extract the parsed json response from a variable in a POST request, store it in a new variable, and then pass that variable in the headers for a subsequent GET request. However, my current approach is not yielding th ...

Adjust the Container's gutters in MaterialUI according to screen sizes

I am trying to adjust the gutters for different screen sizes in my project. I want to turn off the gutters for xs, sm, and md, but have them enabled at xl and larger. Despite following the API documentation, it doesn't seem to be working as expected. ...