Remove green screen in python using numpy and opencv without any predefined functions.

Nagarajramachandran
2 min readFeb 8, 2020

--

Welcome friends.

The above image consists of three images. The first image is key image. The second image is background image. The third image is composited image.

This code is not using any predefined functions. But the concept is the same. From the key image remove the area that contains the green values and replace it with background image.

The pseudo code is

The python code is

I took the 1080p image. The first step is to load two images. Then I loop over the height and width of the key image.The img[i][j][0] denotes blue,img[i][j][1] denotes green,img[i][j][2] denotes red. We want to check the pixel where the green colour occurs. So I put img[i][j][1]>150.The other two (blue and red) wants low values. So I put less than 30 and 50. This value is not constant. I play around with these values to get this output. But make sure of that in RGB green channel contains high values and other two channels contain low values in case that is a green screen.

The time taken is 17 seconds for a 1080p image. This is not an efficient output. I tried on my own without using any predefined function like threshold, masking etc. Thank you for reading this and love learning

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Nagarajramachandran
Nagarajramachandran

Responses (1)

Write a response