Invisibility Cloak using MATLAB and Simulink
Updated 20 Dec 2021
Invisibility Cloak Using MATLAB ® and Simulink ®
This submission contains the implementation of an Invisibility Cloak using image thresholding and segmentation. The implementation uses Interactive Apps from the Image Processing Toolbox ™
To understand the implementation, watch the video on Making Vehicles and Robots See: Image Segmentation and Analysis that introduces the concepts of performing image segmentation and analyzing the regions of interest using interactive apps
About the model
The model showcases the workflow of using the Image Thresholder App and the Image Segmenter App to create the illusion of an invisibility cloak.
- Capture an image of the stationary background from the web camera connected to the system
- Save the image on the workspace as backgroundImage
Color Thresholding and Segmentation
- Capture an image of the colored cloak (cloth) in foreground using a camera connected to the system
- Open Color Thresholder App and move the sliders to detect the color of the cloak and differentiate it from the background
- Use the MATLAB Functions exported from the mask to create a threshold mask and refine the thresholded mask using Image Segmenter App
- Multiply the thresholded mask to the background image to display the background in the colored cloak area giving an illusion of invisibility.
- Multiply the binary complement of the mask with the input video to display the video stream for the rest of the image.
- The mask that contains the colored cloak will use the backgroundImage and the part of the video that does not have the colored cloak use the original video feed.
InvisibilityCloak.slx contains a model which implements the invisibility cloak. Use the MATLAB Function outputs from the Color Thresholder App and the Image Segmenter App in the respective MATLAB Function blocks in the model.
startScript.mlx contains the MATLAB code for the initial setup of the model. This has to be used to capture the background image and the color of the foreground cloak. This is a one-time setup code as long as the placement of the camera, or the background, or the lighting does not change.
Note: The startScript.mlx file needs to be run if the camera placement is changed. The demonstration needs a stable background without any moving objects in the camera frame except the cloak.
How to run the model?
- Open the startScript.mlx script.
- Ensure the correct camera is selected and run the Camera Setup section on the script to initiate the camera.
- Run the Background Setup section of the startScript.mlx file. Ensure to have only the stationary background in this image. Do not include yourself or the cloack in this image.
- Run the Foreground Setup section of the startScript.mlx file. Use the foregroundImage using 'Load Image from the Workspace' in the Color Threshodler App and threshold for the required mask. Export the output as a Function and as Images.
- Use Image Segmenter App to refine the mask exported from the Color Thresholder App. Export the output as a MATLAB Function.
- Open the the Simulink model InvisibilityCloak.slx.
- Replace the contents of the respective MATLAB Functions blocks (i.e. Color Thresholding and Refining Mask) with the App-generated MATLAB functions.
- Run the Clear Variables section on the startScript.mlx script.
- Run the model.
Assumptions in the model
- The model assumes that the camera is stationary.
- The model assumes that the only object moving in the video frame is the foreground with the invisibility cloak.
- Image Processing Toolbox
- Image Acquisition Toolbox ™
- Computer Vision Toolbox ™
- MATLAB Support Package for USB Webcams (Add-On)
- Image Acquisition Toolbox Support Package for OS Generic Video Interface (Add-On)
The license is available in the License file within this repository.
In case of any questions, please reach out to us at email@example.com.
Copyright 2021 The MathWorks, Inc.
Maitreyee Mordekar (2023). Invisibility Cloak using MATLAB and Simulink (https://github.com/mathworks/invisibility-cloak-using-image-segmentation/releases/tag/v1.0.0), GitHub. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.