This example shows you how to develop a Simulink model for an image processing application - color detection by using Simulink® Support Package for Apple iOS Devices.
A color detection algorithm identifies pixels in an image that match a specified color or color range. The color of detected pixels can then be changed to distinguish them from the rest of the image.
This example introduces a workflow to take Simulink model of a color detection algorithm from simulation to deployment onto device:
- Simulate the color detection model
- Deploy the color detection model and use the Video Display block to show simulated data on the iOS device
- Modify the color detection model to use real-time images from the Camera Block
We recommend completing Getting Started with Apple iOS Devices example.
- iPhone, iPod or iPad
- USB cable to connect the device to host computer
Task 1 - Simulate Model on Host Computer
In this task, you will simulate color detection model and observe results for the images from workspace.
1. Open the Color Detection on Images Model
2. Load and display a sample color image into the MATLAB workspace by executing the following command in the MATLAB command window:
RGB_image = imread('peppers.png'); imshow(RGB_image)
3. In the model, double click on the Reference Color block to open the block mask.
4. In the block mask, set the Constant value field to the vector [ 58, 68, 117 ] to detect the color purple in the image. The vector value represents the red, green, and blue components of the color for detection (e.g. [R, G, B] ).
5. In the model, click the Run button on the toolbar to run the simulation. When the simulation completes, you can see the resulting image where the originally purple regions are now white.
6. (Optionally) You can modify the value of the Reference Color block and run the simulation again to isolate different color regions from the image.
Task 2 - Run Model on Device
In this task, you will create a new model to use the Video Display block and deploy the model algorithm to the device
1. Open a new Simulink model and copy the contents of the first model into the new model.
2. In the new model, remove the MATLAB Function image_display block.
3. From the Simulink Library Browser, add the iOS Video Display block to the model. A pre-configured model is included for your convenience.
4. Connect your configured iOS device to your host computer. If you have not previously configured your device, run targetupdater from the MATLAB command prompt.
5. In your Simulink model, click Simulation > Model Configuration Parameters to open Configuration Parameters dialog.
6. Select the Hardware Implementation pane and set the Hardware board to Apple iOS Device.
7. In your Simulink model, click the Deploy to Hardware button on the toolbar.
8. The image with the masked colors will appear on your device screen similar to the figure shown below.
Task 3 - Run Model on Device with Real-time Video
In this task, you will update the previous model to use frames captured from your iOS device camera allowing for color detection in real-time images.
1. Using the model created in Task 2, remove the Constant blocks labelled R_inp, G_inp, and B_inp.
2. From the Simulink Library Browser, add the iOS Camera block to the model.
3. Connect the R, G, and B ports of the Camera block to the R_in, G_in, and B_in ports of the Color Detection block, respectively. A pre-configured model is included for your convenience.
4. In your Simulink model, click the Deploy to Hardware button on the toolbar.
5. The camera images with the masked colors appear on your device screen similar to the figure shown below.
Other Things to Try
- Change the detection algorithm by modifying the threshold values used in the Color Detection subsystem.
This example showed you how to take a Simulink model from a pure simulation to a deployed application on your iOS device. This example also demonstrated an image processing algorithm implementation by using Simulink Support Package for Apple iOS Devices.