Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Pixel operations on a very large image in c#

Pixel operations on a very large image in c#

Scheduled Pinned Locked Moved C#
debuggingcsharpgraphicsperformancetutorial
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    safee ullah
    wrote on last edited by
    #1

    Hello folks, I have a rather large image, whose size is around 6000 x 5000 pixels... I would like to perfom image normalization and other such operations...which include some mathematical calculation for each pixel.. But when I do this on my image, it take about 20 mins to finish... How to speed it up...?? Here is the normalization code which I am running.. public void NormalizeImage(ref Bitmap objBitmap, int iMaxColor) { DateTime dt = System.DateTime.Now; System.Diagnostics.Trace.WriteLine(" Normalizing Image: " + dt); int iX = objBitmap.Size.Width; int iY = objBitmap.Size.Height; int iMaxINTColor = 16777215; try { for (int i = 0; i < iX; i++) { for (int j = 0; j < iY; j++) { int iPrevColorVal = objBitmap.GetPixel(i, j).ToArgb(); //if (iPrevColorVal < 0) // iPrevColorVal = iPrevColorVal * -1; int iNormalizedVal = System.Convert.ToInt32(Math.Pow((iPrevColorVal / iMaxColor), 1)) * iMaxINTColor; objBitmap.SetPixel(i, j, Color.FromArgb(iNormalizedVal)); } } } catch { System.Diagnostics.Debug.Assert(false); } DateTime dt2 = System.DateTime.Now; System.Diagnostics.Trace.WriteLine("Done Normalizing Image:" + dt2); }

    J E M 3 Replies Last reply
    0
    • S safee ullah

      Hello folks, I have a rather large image, whose size is around 6000 x 5000 pixels... I would like to perfom image normalization and other such operations...which include some mathematical calculation for each pixel.. But when I do this on my image, it take about 20 mins to finish... How to speed it up...?? Here is the normalization code which I am running.. public void NormalizeImage(ref Bitmap objBitmap, int iMaxColor) { DateTime dt = System.DateTime.Now; System.Diagnostics.Trace.WriteLine(" Normalizing Image: " + dt); int iX = objBitmap.Size.Width; int iY = objBitmap.Size.Height; int iMaxINTColor = 16777215; try { for (int i = 0; i < iX; i++) { for (int j = 0; j < iY; j++) { int iPrevColorVal = objBitmap.GetPixel(i, j).ToArgb(); //if (iPrevColorVal < 0) // iPrevColorVal = iPrevColorVal * -1; int iNormalizedVal = System.Convert.ToInt32(Math.Pow((iPrevColorVal / iMaxColor), 1)) * iMaxINTColor; objBitmap.SetPixel(i, j, Color.FromArgb(iNormalizedVal)); } } } catch { System.Diagnostics.Debug.Assert(false); } DateTime dt2 = System.DateTime.Now; System.Diagnostics.Trace.WriteLine("Done Normalizing Image:" + dt2); }

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      Hi Safee, The problem is the call to SetPixel. It's horribly slow. You can use the free .NET library FastBitmap[^] to speed up pixel operations, which will result in your algorithm being much faster.

      Tech, life, family, faith: Give me a visit. I'm currently blogging about: I Plead (audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

      1 Reply Last reply
      0
      • S safee ullah

        Hello folks, I have a rather large image, whose size is around 6000 x 5000 pixels... I would like to perfom image normalization and other such operations...which include some mathematical calculation for each pixel.. But when I do this on my image, it take about 20 mins to finish... How to speed it up...?? Here is the normalization code which I am running.. public void NormalizeImage(ref Bitmap objBitmap, int iMaxColor) { DateTime dt = System.DateTime.Now; System.Diagnostics.Trace.WriteLine(" Normalizing Image: " + dt); int iX = objBitmap.Size.Width; int iY = objBitmap.Size.Height; int iMaxINTColor = 16777215; try { for (int i = 0; i < iX; i++) { for (int j = 0; j < iY; j++) { int iPrevColorVal = objBitmap.GetPixel(i, j).ToArgb(); //if (iPrevColorVal < 0) // iPrevColorVal = iPrevColorVal * -1; int iNormalizedVal = System.Convert.ToInt32(Math.Pow((iPrevColorVal / iMaxColor), 1)) * iMaxINTColor; objBitmap.SetPixel(i, j, Color.FromArgb(iNormalizedVal)); } } } catch { System.Diagnostics.Debug.Assert(false); } DateTime dt2 = System.DateTime.Now; System.Diagnostics.Trace.WriteLine("Done Normalizing Image:" + dt2); }

        E Offline
        E Offline
        ekynox
        wrote on last edited by
        #3

        refer to the links I made in this post which will make your calculations fly. http://www.codeproject.com/script/comments/forums.asp?forumid=1649&select=2206729&df=100#xx2206729xx[^]

        1 Reply Last reply
        0
        • S safee ullah

          Hello folks, I have a rather large image, whose size is around 6000 x 5000 pixels... I would like to perfom image normalization and other such operations...which include some mathematical calculation for each pixel.. But when I do this on my image, it take about 20 mins to finish... How to speed it up...?? Here is the normalization code which I am running.. public void NormalizeImage(ref Bitmap objBitmap, int iMaxColor) { DateTime dt = System.DateTime.Now; System.Diagnostics.Trace.WriteLine(" Normalizing Image: " + dt); int iX = objBitmap.Size.Width; int iY = objBitmap.Size.Height; int iMaxINTColor = 16777215; try { for (int i = 0; i < iX; i++) { for (int j = 0; j < iY; j++) { int iPrevColorVal = objBitmap.GetPixel(i, j).ToArgb(); //if (iPrevColorVal < 0) // iPrevColorVal = iPrevColorVal * -1; int iNormalizedVal = System.Convert.ToInt32(Math.Pow((iPrevColorVal / iMaxColor), 1)) * iMaxINTColor; objBitmap.SetPixel(i, j, Color.FromArgb(iNormalizedVal)); } } } catch { System.Diagnostics.Debug.Assert(false); } DateTime dt2 = System.DateTime.Now; System.Diagnostics.Trace.WriteLine("Done Normalizing Image:" + dt2); }

          M Offline
          M Offline
          mav northwind
          wrote on last edited by
          #4

          Hi! There's an excellent series of articles here dealing with the topic. Starting here: http://www.codeproject.com/cs/media/csharpgraphicfilters11.asp[^]

          Regards, mav -- Black holes are the places where God divided by 0...

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups