Hello...
First of all hello to everyone... this is my first post. I did some 'googling' for help with C code and found this place, the reason I need help is because I am working on a (what I consider hard) project and (only) a week and a half to complete it.

Project Details...
To write a C code which extracts the foreground and replaces the background, in other words, chroma key programming, or blue screen editing. Taking a part of an image and replacing the background.

Basically, I have 125 subsequent frames, in which people are moving in and out the frames. The background consists of bushes and trees. The people are walking on a sidewalk. The task at hand is to extract these people and place them walking on an output image, an image of the beach.

So, basically the task consists of... reading in input_image0001.jpg, extracting the foreground, replacing the background with beach.jpg and creating output_image0001.jpg.

What I Know...
So, background information about me: I am not by far a talented coder, but I do love coding and learning. So, I'm here asking for help. So far, I know how to read in the image, i know how write out an image, i know how to isolate each pixel, and "play" with the RGB values.

The input image is 640x140 & the output image is 640x480. I am already aware that vertical offset is going to be necessary to transpose the foreground onto the beach, so the people do not look like they are walking on water, lol.

What I Need Help With...

1. I am trying to figure out an algorithm that will help me extract the people (and clothing, purses, hats, etc) from the original image. The people are not of the same race, therefore not the same color, nor are their clothes the same color. The background is the only thing somewhat constant. I've been considering a "sum of absolute differences." I am confused about how to handle this, because I considered subtracting pixels but then I'm not sure what to subtract from?

One idea I had was if I could somehow run the program to read in all 125 images at the same time and subtract them from each other, meaning any of the background not covered by a person would just be deleted and then take the result and add that to 125 output images. Sounds Crazy?


This is all I can think about for Day 0, it's getting late for me, I'' check back constantly. So, any help is gratelly appreciated it. Thank you and I hope you all have a wonderful Monday.

Sincerely,

I am Confused

Recommended Answers

All 4 Replies

If you're not an experienced programmer, this problem will be near impossible to complete in only one week. With that said:

Is the background static or is the camera moving and therefore the background moving?
If the background is static you should loop through the 125 images and compare each one with the previous and deleting pixels that stayed the same and keeping all the others. Then replace the deleted pixels with the pixels from the new image. This means the two pictures would have to be the exact same dimensions.

Niek

Focus on what "isBackground" rather than everything else.

If it's background, replace with corresponding pixel from background image, otherwise just copy the pixel.

This could be easily a 3-6 months project, provided some one gives your a readymade image processing algorithm.

Ok, so I've been thinking about this and I've come up with sort of a solution and I need opinions and help.

First of all, I'm going to use the first 5 frames to create a background model, basically train the background.


To train the background, I'm going to track an average & standard deviation for RGB or pixel (i'm not sure which yet) values of 5 frames.

Once, I have a background model, I will compare the next frame to this background model. If the new value is less than a set # above the standard deviation, it is a background pixel and therefore deleted.

so in the end, i will only have 120 output images, which is fine.


The only thing that is left is:
1. implementing this "training method."
2. figuring out how to read in 5 images at a time.
3. figure out how to write a script that takes in 120 input images, applies the code, and outputs 120 images.

any help is appreciated... thank you.

- i am confused

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.