Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to map colors

Hello, I want to map some colors in a image to another color the colors are available as HSV (8UC3).

For example:

mapping all pixels with H= 90, S= 128, V = 128 to H= 70, S= 128, V = 128
mapping all pixels with H= 100, S= 128, V = 128 to H= 110, S= 128, V = 128
and so on...

I know about:

  • cv::InRange: very slow, if I have a big map
  • cv::LUT: allows only 256 colors?

has someone an idea or a solution for this problem?

best regards

How to map colors

Hello, I want to map some colors in a image to another color the colors are available as HSV (8UC3).

For example:

mapping all pixels with H= 90, S= 128, V = 128 to H= 70, S= 128, V = 128
mapping all pixels with H= 100, S= 128, V = 128 to H= 110, S= 128, V = 128
and so on...

I know about:

  • cv::InRange: very slow, if I have a big map
  • cv::LUT: allows only 256 colors?

has someone an idea or a solution for this problem?

For a first approach it suffice to get a mask of all these colors.

best regards

How to map colors

Hello, I want to map some colors in a image to another color the colors are available as HSV (8UC3).

For example:

mapping all pixels with H= 90, S= 128, V = 128 to H= 70, S= 128, V = 128
mapping all pixels with H= 100, S= 128, V = 128 to H= 110, S= 128, V = 128
and so on...

I know about:

  • cv::InRange: very slow, if I have a big map
  • cv::LUT: allows only 256 colors?

has someone an idea or a solution for this problem?

For a first approach it suffice to get a mask of all these colors.

EDIT

one idea: iterate the image, and create a map from all colors associated by pixels (color[H,S,V] -> vector of (X,Y)- Coordinate) after that I can iterate the colors I want to map and set all pixel of the vector to the new color. But this solution is very slow, I think but maybe much faster as cv::inrange ? )(for maybe 5,000 colors)

best regards

How to map colors

Hello, I want to map some colors in a image to another color the colors are available as HSV (8UC3).

For example:

mapping all pixels with H= 90, S= 128, V = 128 to H= 70, S= 128, V = 128
mapping all pixels with H= 100, S= 128, V = 128 to H= 110, S= 128, V = 128
and so on...

I know about:

  • cv::InRange: very slow, if I have a big map
  • cv::LUT: allows only 256 colors?

has someone an idea or a solution for this problem?

For a first approach it suffice to get a mask of all these colors.

EDIT

one idea: iterate the image, and create a map from all colors associated by pixels (color[H,S,V] -> vector of (X,Y)- Coordinate) after that I can iterate the colors I want to map change and set all pixel of the vector to the new color. But this This solution is very slow, I think but maybe much faster as cv::inrange ? )(for (for maybe 5,000 colors)colors) What do you think?

best regards

How to map colors

Hello, I want to map some colors in a image to another color the colors are available as HSV (8UC3).

For example:

mapping all pixels with H= 90, S= 128, V = 128 to H= 70, S= 128, V = 128
mapping all pixels with H= 100, S= 128, V = 128 to H= 110, S= 128, V = 128
and so on...

I know about:

  • cv::InRange: very slow, if I have a big map
  • cv::LUT: allows only 256 colors?

has someone an idea or a solution for this problem?

For a first approach it suffice to get a mask of all these colors.

EDIT

one idea: iterate the image, and create a map from all colors associated by pixels (color[H,S,V] -> vector of (X,Y)- Coordinate) after that I can iterate the colors I want to change and set all pixel of the vector to the new color. This solution is very slow, I think but maybe much faster as cv::inrange ? (for maybe 5,000 colors) What do you think?

EDIT 2

I've tested my idea on a i5 with a color wheel image (2400 x 2400 pixels) in RGB - space In this test I save the pointers to the pixel in a map (vector of iterators associated by a color id) After that, I iterate all colors in the map (65453 colors) and set the inverted color to each pixel of the vector This solution needs round about 2,5 seconds (I meassured with getTickCount()). Faster than a concatination of cv::inrange Maybe someone has another solution, that is faster than this? best regards

How to map colors

Hello, I want to map some colors in a image to another color the colors are available as HSV (8UC3).

For example:

mapping all pixels with H= 90, S= 128, V = 128 to H= 70, S= 128, V = 128
mapping all pixels with H= 100, S= 128, V = 128 to H= 110, S= 128, V = 128
and so on...

I know about:

  • cv::InRange: very slow, if I have a big map
  • cv::LUT: allows only 256 colors?

has someone an idea or a solution for this problem?

For a first approach it suffice to get a mask of all these colors.

EDIT

one idea: iterate the image, and create a map from all colors associated by pixels (color[H,S,V] -> vector of (X,Y)- Coordinate) after that I can iterate the colors I want to change and set all pixel of the vector to the new color. This solution is very slow, I think but maybe much faster as cv::inrange ? (for maybe 5,000 colors) What do you think?

EDIT 2

I've tested my idea on a i5 with a color wheel image (2400 x 2400 pixels) in RGB - space image description

In this test I save the pointers to the pixel in a map (vector of iterators associated by a color id) After that, I iterate all colors in the map (65453 colors) and set the inverted color to each pixel of the vector This solution needs round about 2,5 seconds (I meassured with getTickCount()). Faster than a concatination of cv::inrange Maybe someone has another solution, that is faster than this? best regards

How to map colors

Hello, I want to map some colors in a image to another color the colors are available as HSV (8UC3).

For example:

mapping all pixels with H= 90, S= 128, V = 128 to H= 70, S= 128, V = 128
mapping all pixels with H= 100, S= 128, V = 128 to H= 110, S= 128, V = 128
and so on...

I know about:

  • cv::InRange: very slow, if I have a big map
  • cv::LUT: allows only 256 colors?

has someone an idea or a solution for this problem?

For a first approach it suffice to get a mask of all these colors.

EDIT

one idea: iterate the image, and create a map from all colors associated by pixels (color[H,S,V] -> vector of (X,Y)- Coordinate) after that I can iterate the colors I want to change and set all pixel of the vector to the new color. This solution is very slow, I think but maybe much faster as cv::inrange ? (for maybe 5,000 colors) What do you think?

EDIT 2

I've tested my idea on a i5 with a color wheel image (2400 x 2400 pixels) in RGB - space image description

In this test I save the pointers to the pixel in a map (vector of iterators associated by a color id) After that, I iterate all colors in the map (65453 colors) and set the inverted color to each pixel of the vector This solution needs round about 2,5 seconds (I meassured with getTickCount()). Faster than a concatination of cv::inrange cv::inrange

Maybe someone has another solution, that is faster than this? this?

best regards

How to map colors

Hello, I want to map some colors in a image to another color the colors are available as HSV (8UC3).

For example:

mapping all pixels with H= 90, S= 128, V = 128 to H= 70, S= 128, V = 128
mapping all pixels with H= 100, S= 128, V = 128 to H= 110, S= 128, V = 128
and so on...

I know about:

  • cv::InRange: very slow, if I have a big map
  • cv::LUT: allows only 256 colors?

has someone an idea or a solution for this problem?

For a first approach it suffice to get a mask of all these colors.

EDIT

one idea: iterate the image, and create a map from all colors associated by pixels (color[H,S,V] -> vector of (X,Y)- Coordinate) after that I can iterate the colors I want to change and set all pixel of the vector to the new color. This solution is very slow, I think but maybe much faster as cv::inrange ? (for maybe 5,000 colors) What do you think?

EDIT 2

I've tested my idea on a i5 with a color wheel image (2400 x 2400 pixels) in RGB - space image description

In this test I save the pointers to the pixel in a map (vector of iterators associated by a color id) After that, I iterate all colors in the map (65453 colors) and set the inverted color to each pixel of the vector This solution needs round about 2,5 seconds (I meassured with getTickCount()). ) and after some optimazion I run it with 1 second. Faster than a concatination of cv::inrange

Maybe someone has another solution, that is faster than this?

best regards