Hi friends, I have an image(Jpeg). I want to accept the color code from the user and manipulate the image to get the new image having the supplied color from the original image. Ex. In an Indian flag, there are 3 colors(like color filled bars. Red, White,
Green). If I supply red color (FF0000), the new image should be only 1 bar having the red color. How can I do it? How can I manipulate images? Thanks in advance
Here's a sample function written in C# that accepts a bitmap image, the color to be replaces and the desired color, then returns the image result based on what you've specified in your thread. You may modify it as you wish..
I have not tried this but this is the algorithm you can use...
//this function accepts and return
bitmap images public
Bitmap
replaceBluetoBlack(Bitmap
sourceImage, Color
ColorToBeReplaced, Color
ColorToReplace) { Bitmap
renderedImage = sourceImage; int x, y;
// basically an image is composed of two dimensional array of pixels
// so we are just scanning 1 row at a time for (y = 0; y < renderedImage.Height; y++) { for (x = 0; x < renderedImage.Width; x++) { // each pixel is usually composed of Red, Gren and Blue values
Color
pixelColor = renderedImage.GetPixel(x, y);
// in this example we will just replace the target pixels into the desired
color // the RGB equivalent of blue is R:0,G:0,B:255 or #0000FF // each RGB values can have a value of 0-255 (00-FF)
//we construct the RGB values of the color to replace int R = ColorToBeReplaced.R; int G = ColorToBeReplaced.G; int B= ColorToBeReplaced.B;
if((pixelColor.R = R)&&(pixelColor.G = G)&&(pixelColor.B = B)) { // this constructs the desired color
Color
newColor = Color.FromArgb(ColorToReplace.R, ColorToReplace.G,
ColorToReplace.B);
//we set the current pixel into the color
renderedImage.SetPixel(x, y, newColor); } } } return renderedImage; }
If your original image have sharp areas with no antialias (wich works as a color zone border softening), then you can use a technique called color transformation to convert every pixel but the ones with the color you want to extract to your background color
(or even transparent if your image format supports it) as explained here:
If your original image have sharp areas with no antialias (wich works as a color zone border softening), then you can use a technique called color transformation to convert every pixel but the ones with the color you want to extract to your background color
(or even transparent if your image format supports it) as explained here:
Member
3 Points
24 Posts
Image processing
May 17, 2007 06:40 AM|mrajanikrishna|LINK
Hi friends, I have an image(Jpeg). I want to accept the color code from the user and manipulate the image to get the new image having the supplied color from the original image. Ex. In an Indian flag, there are 3 colors(like color filled bars. Red, White, Green). If I supply red color (FF0000), the new image should be only 1 bar having the red color. How can I do it? How can I manipulate images? Thanks in advance
None
0 Points
3 Posts
Re: Image processing
Jun 24, 2007 03:50 AM|safir187|LINK
Hello you can use Bitmap.setPixel(int x, int y) and Bitmap.getPixel(int x, int y) to do every thing...
there are much other ways but for that example you gave its more easier...
None
0 Points
3 Posts
Re: Image processing
May 13, 2011 09:32 AM|jnabor|LINK
Here's a sample function written in C# that accepts a bitmap image, the color to be replaces and the desired color, then returns the image result based on what you've specified in your thread. You may modify it as you wish..
I have not tried this but this is the algorithm you can use...
//this function accepts and return bitmap images
public Bitmap replaceBluetoBlack(Bitmap sourceImage, Color ColorToBeReplaced, Color ColorToReplace)
{
Bitmap renderedImage = sourceImage;
int x, y;
// basically an image is composed of two dimensional array of pixels
// so we are just scanning 1 row at a time
for (y = 0; y < renderedImage.Height; y++)
{
for (x = 0; x < renderedImage.Width; x++)
{
// each pixel is usually composed of Red, Gren and Blue values
Color pixelColor = renderedImage.GetPixel(x, y);
// in this example we will just replace the target pixels into the desired color
// the RGB equivalent of blue is R:0,G:0,B:255 or #0000FF
// each RGB values can have a value of 0-255 (00-FF)
//we construct the RGB values of the color to replace
int R = ColorToBeReplaced.R;
int G = ColorToBeReplaced.G;
int B= ColorToBeReplaced.B;
if((pixelColor.R = R)&&(pixelColor.G = G)&&(pixelColor.B = B))
{
// this constructs the desired color
Color newColor = Color.FromArgb(ColorToReplace.R, ColorToReplace.G, ColorToReplace.B);
//we set the current pixel into the color
renderedImage.SetPixel(x, y, newColor);
}
}
}
return renderedImage;
}
I HOPE THAT HELPS!!!
Member
700 Points
229 Posts
Re: Image processing
May 13, 2011 04:42 PM|OnoSendai|LINK
Hey mrajanikrishna!
i can envision two principal approaches:
If your original image have sharp areas with no antialias (wich works as a color zone border softening), then you can use a technique called color transformation to convert every pixel but the ones with the color you want to extract to your background color (or even transparent if your image format supports it) as explained here:
http://www.aspfree.com/c/a/C-Sharp/Color-Transformation-Applications-in-Csharp-GDIplus-Programming-3/
If that`s not the case, then maybe you can try working with a similarity algorythm and then tinting the image.
Hope it works for you.
Member
700 Points
229 Posts
Re: Image processing
May 13, 2011 04:45 PM|OnoSendai|LINK
Hey mrajanikrishna!
i can envision two principal approaches:
If your original image have sharp areas with no antialias (wich works as a color zone border softening), then you can use a technique called color transformation to convert every pixel but the ones with the color you want to extract to your background color (or even transparent if your image format supports it) as explained here:
http://www.aspfree.com/c/a/C-Sharp/Color-Transformation-Applications-in-Csharp-GDIplus-Programming-3/
If that`s not the case, then maybe you can try working with a similarity algorythm and then tinting the image.
Hope it works for you.