K
K
kir_cipher2017-05-03 23:22:36
Images
kir_cipher, 2017-05-03 23:22:36

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);
                    ... Некоторые действия с пикселем ...
                 }

I needed the ability to exclude some areas from the processing area. Well, I thought that, they say, the question is bullshit: now I will ask an array of points that do not need to be processed, and before receiving the pixel and processing it, I will put it in the hat! But it was not there. The method started to work just as hell slowly (and when I chose half of the entire image to exclude for testing, I did not wait for the result even within 4 minutes). I tried to implement multithreading to solve this problem. But I almost burned my CPU (99% load) xD In general, you need to somehow optimize this thing (or implement non-clumsy multithreading), but there are no ideas how to do it. So I turn to you for advice on this difficult matter!if (ExceptPoints.Contains(new Point(x,y)))
PS - excluded areas are initially set by circles with a random radius. But what to check if a point is included in one of the circles, what to check if it is among the array containing all the points of these circles, one thing comes out in time

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Peter, 2017-05-04
@kir_cipher

If you want speed, then forget about GetPixel
UseBitmap.LockBits

G
GavriKos, 2017-05-04
@GavriKos

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 question

Ask a Question

731 491 924 answers to any question