Task 1 - Simulate Model on Host Computer

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.

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.

Summary

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.

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window.
Web browsers do not support MATLAB commands.

Was this topic helpful?

Select Your Country

Choose your country to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .