{"id":18425,"date":"2025-10-01T10:44:50","date_gmt":"2025-10-01T14:44:50","guid":{"rendered":"https:\/\/blogs.mathworks.com\/deep-learning\/?p=18425"},"modified":"2025-10-01T10:45:55","modified_gmt":"2025-10-01T14:45:55","slug":"tennis-analysis-with-ai-interactive-ground-truth-labeling","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/deep-learning\/2025\/10\/01\/tennis-analysis-with-ai-interactive-ground-truth-labeling\/","title":{"rendered":"Tennis Analysis with AI: Interactive Ground Truth Labeling"},"content":{"rendered":"<h6><\/h6>\r\n<em>This blog post is from <\/em><a href=\"https:\/\/www.linkedin.com\/in\/cory-hoi-5a3373235\/\"><em>Cory Hoi<\/em><\/a><em>, Engineer at MathWorks Engineering Development Group.<\/em>\r\n<h6><\/h6>\r\n&nbsp;\r\n<h6><\/h6>\r\nWith the rapid advancement of <a href=\"https:\/\/www.mathworks.com\/discovery\/artificial-intelligence.html\">artificial intelligence (AI)<\/a>, harnessing its power is now more accessible than ever. I imagine that the arrival of the personal computer was equally transformative. We are now seeing \u00a0AI advancements in areas like <a href=\"https:\/\/www.mathworks.com\/discovery\/computer-vision.html\">computer vision<\/a> and <a href=\"https:\/\/www.mathworks.com\/discovery\/natural-language-processing.html\">natural language processing (NLP)<\/a> being applied in chatbots, healthcare research, transportation, education, and sports. It is everywhere we look \u2013 so integrated into our daily lives that many of us hardly notice its presence. For example, just turn on your TV to your favorite sports broadcast.\r\n<h6><\/h6>\r\nFor me, it\u2019s tennis. At this past Wimbledon, line calls were fully automated, eliminating the need to argue with judges over close calls. Ball tracking and real-time data analysis have also become integral parts of the game, representing a leap forward from sports analytics just five years ago. Players now use AI to study playing patterns and refine their tactics. Yet, as an avid fan, I can\u2019t help but wonder: how does all of this actually work?\r\n<h6><\/h6>\r\nIn this two-part blog post series, I will show you how to build and leverage deep neural networks in MATLAB for object detection. This first blog post focuses on the initial steps of labeling the data. It will go over the many tools available in MATLAB to ease the typical pains of data labeling.\r\n<h6><\/h6>\r\n&nbsp;\r\n<h6><\/h6>\r\n<p style=\"font-size: 20px; color: #c04c0b;\"><strong>Object Detection in Sports<\/strong><\/p>\r\nAs you may have guessed, my sport of choice is tennis. However, the <a href=\"https:\/\/www.mathworks.com\/discovery\/object-detection.html\">object detection<\/a> methods described here have many applications, in other sports like basketball and football, and beyond sports like in autonomous vehicles. Object detection in tennis has greatly improved my viewing experience in recent years. This is evident when looking at instant replays of tennis points with the ball clearly marked and tracked.\r\n<h6><\/h6>\r\nData preparation is an arguably crucial but often overlooked step in any AI task. It involves labelling the dataset to create ground truth data for training, and also preparing the dataset into the correct form.\r\n<h6><\/h6>\r\n&nbsp;\r\n<h6><\/h6>\r\n<p style=\"font-size: 20px; color: #c04c0b;\"><strong>Interactive Video Labeling<\/strong><\/p>\r\nIn MATLAB, video labeling is made easy with the <a href=\"https:\/\/www.mathworks.com\/help\/vision\/ug\/get-started-with-the-video-labeler.html\">Video Labeler<\/a> app. The app allows you to interactively label shapes or regions of interest (ROI) with rectangles, polylines, pixels, and polygon ROI labels. In this post, we are using Video Labeler to label the tennis ball, and also the tennis court in our dataset.\r\n<h6><\/h6>\r\nOpen the Video Labeler app from the <strong>Apps<\/strong> tab, under <strong>Image Processing and Computer Vision<\/strong>. Create a new project and import the video from the trainingData folder.\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" width=\"601\" height=\"79\" class=\"alignnone size-full wp-image-18437\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/09\/post1_image1.png\" alt=\"\" \/>\r\n<h6><\/h6>\r\n&nbsp;\r\n<h6><\/h6>\r\nAfter loading the video, the app will display the first frame in the middle of the screen. In the panel just below, you can navigate between frames with the left and right arrows.\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" width=\"1379\" height=\"704\" class=\"alignnone size-full wp-image-18449\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/09\/post1_image2.png\" alt=\"\" \/>\r\n<h6><\/h6>\r\n<em>Video Labeler<\/em>\r\n<h6><\/h6>\r\n&nbsp;\r\n<h6><\/h6>\r\n<p style=\"font-size: 20px; color: #c04c0b;\"><strong>Manual vs Automatic Labeling<\/strong><\/p>\r\nIn MATLAB, there are numerous ways to label a dataset. For example, you can define bounding boxes around the people playing tennis and give them the label name \u201cperson\u201d. You can also define lines to label the lines on the court as linear objects. However, for this project, let\u2019s label pixels by identifying the tennis ball, give it the label name \u201cball\u201d, and assign the Color to green.\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" width=\"459\" height=\"236\" class=\"alignnone size-full wp-image-18494\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/09\/image3.png\" alt=\"\" \/>\r\n<h6><\/h6>\r\nAfter adding the label, it will appear in the ROI Label Definitions pane to the left. This allows you to easily switch between object labels if there are multiple objects in a single image. There are multiple manual \u00a0and automatic algorithms available.\r\n<h6><\/h6>\r\nManual algorithms such as Polygon and Brush, allow you to exactly define the area to label. While automation algorithms leverage a range of techniques to speed up and ease typical pains of the labeling process. Some additional \u00a0automation algorithms include Superpixel, Segment Anything, and Assisted Freehand.\r\n<h6><\/h6>\r\nFor example, in the following video, the ball and the person are manually labeled with the Brush and the Polygon. The ball is easy to label since it only takes a single click with the brush tool. However, labeling the person is more challenging. The polygon tool uses straight lines that don't automatically snap to the person's edges. This label could be improved by using much shorter line segments, though this would require more time.\r\n<h6><\/h6>\r\n<div class=\"row\"><div class=\"col-xs-12 containing-block\"><div class=\"bc-outer-container add_margin_20\"><videoplayer><div class=\"video-js-container\"><video data-video-id=\"6379620866112\" data-video-category=\"blog\" data-autostart=\"false\" data-account=\"62009828001\" data-omniture-account=\"mathwgbl\" data-player=\"rJ9XCz2Sx\" data-embed=\"default\" id=\"mathworks-brightcove-player\" class=\"video-js\" controls><\/video><script src=\"\/\/players.brightcove.net\/62009828001\/rJ9XCz2Sx_default\/index.min.js\"><\/script><script>if (typeof(playerLoaded) === 'undefined') {var playerLoaded = false;}(function isVideojsDefined() {if (typeof(videojs) !== 'undefined') {videojs(\"mathworks-brightcove-player\").on('loadedmetadata', function() {playerLoaded = true;});} else {setTimeout(isVideojsDefined, 10);}})();<\/script><\/div><\/videoplayer><\/div><\/div><\/div>\r\n<em>Manually labeling the ball and person<\/em>\r\n<h6><\/h6>\r\nOne downside of manually labeling frames are miss-clicks. In these instances, you can delete the labels by right clicking the frame and clicking Delete All Pixel Labels or use the shortcut (Ctrl + Shift + Delete). Alternatively, you can use one of the semi-automated algorithms to speed up the process. For example, in the following video, the Assisted Freehand algorithm automatically detects edges along the person. Every left click creates a vertex point and results in a new pivot point for a subsequent line. Using left clicks more frequently will result in higher accuracy.\r\n<h6><\/h6>\r\n<div class=\"row\"><div class=\"col-xs-12 containing-block\"><div class=\"bc-outer-container add_margin_20\"><videoplayer><div class=\"video-js-container\"><video data-video-id=\"6379616381112\" data-video-category=\"blog\" data-autostart=\"false\" data-account=\"62009828001\" data-omniture-account=\"mathwgbl\" data-player=\"rJ9XCz2Sx\" data-embed=\"default\" id=\"mathworks-brightcove-player\" class=\"video-js\" controls><\/video><script src=\"\/\/players.brightcove.net\/62009828001\/rJ9XCz2Sx_default\/index.min.js\"><\/script><script>if (typeof(playerLoaded) === 'undefined') {var playerLoaded = false;}(function isVideojsDefined() {if (typeof(videojs) !== 'undefined') {videojs(\"mathworks-brightcove-player\").on('loadedmetadata', function() {playerLoaded = true;});} else {setTimeout(isVideojsDefined, 10);}})();<\/script><\/div><\/videoplayer><\/div><\/div><\/div>\r\n<em>Automatic object labeling with SAM<\/em>\r\n<h6><\/h6>\r\nSAM automatically detects the edges and segments in the frame with just a few clicks. In the example above, the singles tennis court is labeled around the tennis player while the doubles court, background, and out-of-bound regions are not labeled.\r\n<h6><\/h6>\r\nYou can also consider other automation algorithms for labeling:\r\n<ul>\r\n \t<li>The Flood Fill algorithm is efficient in labeling a group of connected pixels that have a similar color. However, when colors are similar in values, the Flood Fill tool is not recommended.<\/li>\r\n \t<li>The Smart Polygon algorithm might be a good alternative for discriminating between similarly colored objects. It estimates the shape of an object of interest within the polygon that you draw. This is useful when the object is not a simple polygon.<\/li>\r\n \t<li>The Superpixel algorithm overlays a grid of super pixels with adjustable sizes. For example, in the following GIF, the pixelated grid is initially too large. After the grid is refined, the court can be more accurately labeled.<\/li>\r\n<\/ul>\r\n<div class=\"row\"><div class=\"col-xs-12 containing-block\"><div class=\"bc-outer-container add_margin_20\"><videoplayer><div class=\"video-js-container\"><video data-video-id=\"6379621173112\" data-video-category=\"blog\" data-autostart=\"false\" data-account=\"62009828001\" data-omniture-account=\"mathwgbl\" data-player=\"rJ9XCz2Sx\" data-embed=\"default\" id=\"mathworks-brightcove-player\" class=\"video-js\" controls><\/video><script src=\"\/\/players.brightcove.net\/62009828001\/rJ9XCz2Sx_default\/index.min.js\"><\/script><script>if (typeof(playerLoaded) === 'undefined') {var playerLoaded = false;}(function isVideojsDefined() {if (typeof(videojs) !== 'undefined') {videojs(\"mathworks-brightcove-player\").on('loadedmetadata', function() {playerLoaded = true;});} else {setTimeout(isVideojsDefined, 10);}})();<\/script><\/div><\/videoplayer><\/div><\/div><\/div>\r\n\r\n<em>Automatic labeling with Assisted Freehand<\/em>\r\n<h6><\/h6>\r\n&nbsp;\r\n<h6><\/h6>\r\n<p style=\"font-size: 20px; color: #c04c0b;\"><strong>Saving Ground Truth<\/strong><\/p>\r\nContinuing to label the frames is straightforward. To label the next frame, click the next frame button. After all the frames have been labeled, the project can be saved, and the data can be exported. Saving the project allows you to reopen it from the same state it was left.\r\n<h6><\/h6>\r\nTo export the data, click the green checkmark in the toolbar and export the data to a file. This will create a gTruth MAT-file that can be loaded into the workspace when training the neural network later.\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" width=\"124\" height=\"210\" class=\"alignnone size-full wp-image-18503\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/09\/post1_image4.png\" alt=\"\" \/>\r\n<h6><\/h6>\r\n&nbsp;\r\n<h6><\/h6>\r\n<p style=\"font-size: 20px; color: #c04c0b;\"><strong>Conclusion<\/strong><\/p>\r\nThis workflow illustrated how the Video Labeler app can be used to label different shapes. It offers a variety of labeling algorithms, each with advantages and disadvantages in different labeling scenarios.\r\n<h6><\/h6>\r\nStay tuned for the next blog post, where the labeled dataset is used to train and test a deep neural network that tracks the tennis ball.\r\n<h6><\/h6>","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/09\/post1_image2.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><p>\r\nThis blog post is from Cory Hoi, Engineer at MathWorks Engineering Development Group.\r\n\r\n&nbsp;\r\n\r\nWith the rapid advancement of artificial intelligence (AI), harnessing its power is now more... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/deep-learning\/2025\/10\/01\/tennis-analysis-with-ai-interactive-ground-truth-labeling\/\">read more >><\/a><\/p>","protected":false},"author":194,"featured_media":18449,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[36,54,9],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/posts\/18425"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/users\/194"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/comments?post=18425"}],"version-history":[{"count":19,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/posts\/18425\/revisions"}],"predecessor-version":[{"id":18551,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/posts\/18425\/revisions\/18551"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/media\/18449"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/media?parent=18425"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/categories?post=18425"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/tags?post=18425"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}