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. LINQ
  4. Query Out pixel data

Query Out pixel data

Scheduled Pinned Locked Moved LINQ
csharpdatabaselinqperformancehelp
4 Posts 2 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I may not be storing this right... I am going through an image and storring the pixel values in a double list (i.e. List>) I am doing this so later I can query a range and obtain a histogram. Currently my method is VERY slow. I was thinking switching to LINQ would speed it up rather than looping. However, my brain got stuck with the double List. Anybody have an idea of how I should store the info and then how I can query it? I would like to send it 2 points (upper left and lower right), or 1 point (upper left) and size.. Or something similar. Thank you in advance.

    "9 Pregnent woman can not have a baby in 1 month" -Uknown

    E 1 Reply Last reply
    0
    • L Lost User

      I may not be storing this right... I am going through an image and storring the pixel values in a double list (i.e. List>) I am doing this so later I can query a range and obtain a histogram. Currently my method is VERY slow. I was thinking switching to LINQ would speed it up rather than looping. However, my brain got stuck with the double List. Anybody have an idea of how I should store the info and then how I can query it? I would like to send it 2 points (upper left and lower right), or 1 point (upper left) and size.. Or something similar. Thank you in advance.

      "9 Pregnent woman can not have a baby in 1 month" -Uknown

      E Offline
      E Offline
      Eslam Afifi
      wrote on last edited by
      #2

      If you're using GetPixel, don't. GetPixel is slow. Instead loop over pixels using pointers as presented here Image Processing for Dummies with C# and GDI+ Part 1 - Per Pixel Filters[^] and build the list. And to speed things a bit, I suggest you loop each 4 (or 3 pixels) and represent the colors as integers instead of Colors. If it isn't the problem, maybe the problem is the query itself. But it should be a simple group by with frequency projection like the post below.

      Eslam Afifi

      L 1 Reply Last reply
      0
      • E Eslam Afifi

        If you're using GetPixel, don't. GetPixel is slow. Instead loop over pixels using pointers as presented here Image Processing for Dummies with C# and GDI+ Part 1 - Per Pixel Filters[^] and build the list. And to speed things a bit, I suggest you loop each 4 (or 3 pixels) and represent the colors as integers instead of Colors. If it isn't the problem, maybe the problem is the query itself. But it should be a simple group by with frequency projection like the post below.

        Eslam Afifi

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        I guess I wasn't entirely clear on what I am trying to speed up. I am already using pointers and filling a container. My container is a double list. Then at some point I need to access the pixels in a rectangle region. I want a histogram of that region (i.e. a count of each pixel value). I am not sure of the best way to be storing this and then querying this.

        "9 Pregnent woman can not have a baby in 1 month" -Uknown

        E 1 Reply Last reply
        0
        • L Lost User

          I guess I wasn't entirely clear on what I am trying to speed up. I am already using pointers and filling a container. My container is a double list. Then at some point I need to access the pixels in a rectangle region. I want a histogram of that region (i.e. a count of each pixel value). I am not sure of the best way to be storing this and then querying this.

          "9 Pregnent woman can not have a baby in 1 month" -Uknown

          E Offline
          E Offline
          Eslam Afifi
          wrote on last edited by
          #4

          If you're doing this operation only once for an image, you can determine while looping with pointers if a color is in the desired area or not and build the list then group or even build the histogram directly. If you would be doing the operation many times for an image, you can build the list the same way you're doing it once then later filter the elements based on the color index in the list using this Where overload[^] before doing the grouping. To know if an index is in an area

          xI = index % width
          yI = index % height

          xI >= x1 &&
          yI >= y1 &&
          xI <= x2 &&
          yI <= y2

          that (x1, y1) is the top-left pixel of the area
          and (x2, y2) is the bottom-right pixel of the area

          A faster method is to determine the index corresponding to the top-left pixel the loop over the list elements inside the area and build the histogram directly (or build an array and group but this is slower and requires more memory).

          Eslam Afifi

          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