1
I got the following for
nested throughout the length of an image bitmap in C#. I would like to rotate the second one with threads to be executed in parallel.
Bitmap alterado = new Bitmap(original.Width, original.Height);
//Convertendo para tons de Cinza
for (int i = 0; i < original.Width; i++)
{
for (int j = 0; j < original.Height; j++)
{
Color corOriginal = original.GetPixel(i, j);
int escalaCinza = (int)((corOriginal.R * 0.3) + (corOriginal.G * 0.49) + (corOriginal.B * 0.11));
Color CorEmEscalaDeCinza = Color.FromArgb(escalaCinza, escalaCinza, escalaCinza);
alterado.SetPixel(i, j, CorEmEscalaDeCinza);
}
}
return alterado;
How can I do ?
But the second for does not depend on the first?
– Jéf Bueno
I wish that when the second is over, that he would increase the first.
– Raphael Prado de Oliveira
And what is the meaning of the parallelism there?
– Jéf Bueno
It would rotate only the j’s output in parallel.
– Raphael Prado de Oliveira
But why? If the first
for
you’ll have to wait for the second one to end?– Jéf Bueno
And what do you want to do? That’s all that matters. In fact, you have a great chance of serving nothing, or even harming: http://answall.com/q/1946/101
– Maniero
If you have a way to rotate the i’s parallel without waiting for the j’s to finish, it’s better
– Raphael Prado de Oliveira
The goal is to transform the color image into black and white. I already have the algorithm that works sequentially. would like to convert it to parallel
– Raphael Prado de Oliveira
If it’s a small image, it doesn’t pay, if it’s multiple images, it’s better to parallelize the images and not the individual algorithm, if it’s a big one, but really big one, the gain will be small, if you have it. And if possible, not everything can be parallelized. That’s why you need to see what you want to do.
– Maniero
It’s a college exercise. I need to do it in a serial and parallel way and compare the two, to see if it pays or not to do it in parallel. I realized that for small images, the sequential algorithm was fast, for larger images (4K resolution) took 23 seconds. I’d like the parallel algorithm to compare.
– Raphael Prado de Oliveira
@Raphaelpradodeoliveira but then the
for
are independent of each other?– Jéf Bueno
They are. Each pixel of the image I walk through, is independent of each other.
– Raphael Prado de Oliveira
Dude, how is it independent if you use the
i
within the second is?– Jéf Bueno
Did the answer help to reach the solution? Do you think you can accept it?
– Maniero