Query Out pixel data
-
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
-
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
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
-
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
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
-
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
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 % heightxI >= x1 &&
yI >= y1 &&
xI <= x2 &&
yI <= y2that (x1, y1) is the top-left pixel of the area
and (x2, y2) is the bottom-right pixel of the areaA 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