Answer the question
In order to leave comments, you need to log in
How to normally exclude some Point array from the image processing area (c#)?
Good day, gentlemen!
The essence of the question is as follows:
I process the photo pixel by pixel:
Bitmap bit = new Bitmap(StartImage);
Size size = bit.Size;
for (int y = 0; y < size.Height; y++)
for (int x = 0; x < size.Width; x++)
{
Color c = bit.GetPixel(x, y);
... Некоторые действия с пикселем ...
}
if (ExceptPoints.Contains(new Point(x,y)))
Answer the question
In order to leave comments, you need to log in
If ExceptPoints is a list, then its Contains is long enough. Moreover, you also make an allocation to it, and so on for each pixel - the wildest number of passes through the array.
Quick option: use HashSet for ExceptPoints, but there is an issue with comparing instances. Perhaps Point will not have to be stored, but encoded in int. Which is still faster.
Another option is to sort ExceptPoints, and each time the search (Contains) starts from the previous found point. In fact - removal from the list, but without removal - because the removal is also long.
Again, sorting can really help out - you need to think about it.
Well, the easiest option is a mask. Those. you are storing a bool array of length equal to the number of pixels, where the value is whether or not to exclude that point. It will be very fast, but uneconomical in terms of memory.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question