1

Im trying to isolate and segment the yellow car body to change the color of it. in order to do that i need to separately identify the body from the image. And continue oration with the remaining white pixels. And im using C#, here the plan

Color d;
Color newColor = Color.YellowGreen;    
for(inti =0;i<carimage.Width;i++){
    for(intj =0;j<carimage.Height;j++){
        d = carimage.GetPixel(i, j);
            if(d.R == 255 && d.G==255 && d.B == 255)
                image.SetPixel(i, j, newColor );
    }
}

simple thresholding will trow the second image where car body is not separated correctly. i tried Aforge.net Fill holes image filter but no significant change has been done to the threshold image. I tried to use color filter but it i did not return a correct output due to color vary of the body. can anyone suggest and solution for this?

Original Image

original image

Threshold Image

threshold image

Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
user1017919
  • 85
  • 2
  • 10
  • Please post the actual code. This code is obviously not the code you actually have in your program, since you have contracted `int i` into `inti`, which won't compile. Also, the code posted would, if corrected, replace the color white with the color green. The images suggests you're doing something else. Please post a coherent question. – Lasse V. Karlsen Nov 14 '11 at 21:39

4 Answers4

2

Instead of thresholding, you might want to look into clustering.

As a quick&dirty test, I've increased the image brightness in HSB space (using Mathematica):

brightnessAdjusted = Image[ Map[#^{1, 1, 0.2} &, ImageData[ColorConvert[img, "HSB"]], {2}], ColorSpace -> "HSB"]

enter image description here

Then I've used simple K-Nearest clustering:

(clusters = ClusteringComponents[ColorConvert[brightnessAdjusted, "RGB"], 3, Method -> "KMeans"]) // Colorize

enter image description here

to find clusters of similar colors in the image (there are many more, probably more suitable clustering algorithms, so you should experiment a little). Then I can just adjust the color in one of the clusters:

Image[MapThread[If[#1 == 2, #2[[{1, 3, 2}]], #2] &, {clusters, ImageData[brightnessAdjusted]}, 2]]

enter image description here

If you want to use thresholding, you should probably use a CIE color space, since euclidian distances in that color space are closer to human perception.

Niki
  • 15,662
  • 5
  • 48
  • 74
0
    I=imread('test.jpg'); 
    I=im2double(rgb2gray(I)); 
    BW=im2bw(I,0.64);imshow(BW)

Gives me :

image

I got the 0.64 threshold by looking at the image's histogram. I suggest you use MATLAB to do image processing as it is much easier. Hope that helps you in colouring the image.

Community
  • 1
  • 1
Has
  • 885
  • 4
  • 13
  • 31
0

I had a similar project few years ago. I can't remember the exact details, but the idea was to shift a (not too small) sliding window over the image, and calculate the average intensity (maybe for R, G and B separately) inside the window at each position. I filled a "threshold image" with these averages, and subtracted it from the original image. There was a scaling factor somewhere, and other tuning stuff, but the point is, such an approach was way better than using a constant threshold.

kol
  • 27,881
  • 12
  • 83
  • 120
0

If you are going to use a set of thresholds, you might be better of selecting yellow hues in the Hue Saturation Value colorspace. See the related SO question.

Community
  • 1
  • 1
Maurits
  • 2,082
  • 3
  • 28
  • 32