Skip to content

Latest commit

 

History

History
64 lines (46 loc) · 3.51 KB

README.md

File metadata and controls

64 lines (46 loc) · 3.51 KB

List of Contents:

  1. Bitwise Operations
    1. Bitwise AND
    2. Bitwise OR
    3. Bitwise XOR
  2. Masking
  3. Working
  4. Usage Instructions
  5. Example Illustration

Bitwise Operations

When we perform masking, we see for either black or white or any colour and perform operations according to it. We can also perform bitwise operations on the image when we need to extract only the required part of the image.

Consider the following input images:

image 1 image 2

The Bitwise operations we can perform on them are:

1. Bitwise AND (A intersection B)

Bitwise AND

2. Bitwise OR (A union B)

Bitwise OR

3. Bitwise XOR (Mutually Exclusive)

Bitwise XOR

and finally Bitwise NOT corresponds to A' and B' with respect to set theory.

Results with a subject and the OpenCV logo image

Masking

Masking is the process of hiding or covering a particular area, so with this code we try to get actual desired PNG's (With transparent background) from fake supposed PNG's you might have downloaded by performing some logical operations. The part with the background gets masked and we are left with the desired image. We do this by checking the RGB values of the input image with a reference value, here we do that using logical operators.

Working

  1. We define a Mat container image which takes in an input image from the user.
  2. We then call our function Mat masking(Mat image) which takes in the user input image as it's argument and returns the final image as another Mat container aka image.
  3. The function achieves it's simple masking operation by comparing the RGB values of pixels with the RGB values of colours to be masked/ignored. if their values match we do not write anything to our new image. If the values of the RGB to be neglected don't match with the current pixel RGB values, we then write it to our new transparent image.
  4. The program then returns the new image, saves it and displays it on the user screen.

Usage

  1. (Optional) If you are facing include errors try changing #include <opencv2/opencv.hpp> to #include <opencv4/opencv2/opencv.hpp> which might potentially resolve your error, or a simple google search will help.
  2. Navigate to ../Pixels_Seminar/4_cv_basics/5_masking
  3. Open terminal in this folder
  4. run make clean to lean out any previous builds
  5. type make SRC=main.cpp to build the executable
  6. You should now have an imshow window open showing you the output as well as a newly created image in your assets folder named bg_free.png which you can view with your image viewer (recommended)

Example

Input Image

Nike.png

Output Image

bg_free.png