How to Easily Get X Y Coordinates from an Image in MATLAB
Автор: vlogize
Загружено: 2025-05-27
Просмотров: 5
Learn how to extract and save coordinates from an image using MATLAB with a simple code example and step-by-step instructions.
---
This video is based on the question https://stackoverflow.com/q/67106290/ asked by the user 'miky98' ( https://stackoverflow.com/u/15645525/ ) and on the answer https://stackoverflow.com/a/67127589/ provided by the user 'MichaelTr7' ( https://stackoverflow.com/u/13669087/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions.
Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: Get X Y coordinates of image
Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/l...
The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license.
If anything seems off to you, please feel free to write me at vlogize [AT] gmail [DOT] com.
---
How to Easily Get X Y Coordinates from an Image in MATLAB
When working with images in MATLAB, you may need to extract specific points by clicking on the image. This is where obtaining the X Y coordinates comes in handy! Whether you're developing an application, analyzing image data, or designing an interface, knowing how to store these coordinates into a matrix can be incredibly beneficial. In this guide, we will walk you through the steps to achieve this efficiently.
The Problem: Extracting X Y Coordinates
Imagine you have an image and you want to select multiple points on it to analyze or store their X Y coordinates in a structured way. If you just click on the image repeatedly, you may find yourself needing the points in a matrix format for further processing. The challenge is to gather those selections and save them properly.
In this blog, we'll use a simple MATLAB script that allows you to click on an image, store the coordinates in an array, and display the stored coordinates as you progress.
The Solution: Step-by-Step Guide
Step 1: Set Up Your Environment
Before diving into the code, make sure you have the following:
MATLAB installed on your computer.
An image file (for the demonstration, we will use tire.tif).
Step 2: Understanding the Code
Here’s a simple yet effective code snippet to help you capture and save X Y coordinates from an image:
[[See Video to Reveal this Text or Code Snippet]]
Code Breakdown:
Initialization: Start with cleaning the command window and clearing any existing variables.
Read and Display Image: Load your image using imread and display it with imshow while enabling axes for reference.
Coordinate Arrays: Preallocate arrays for x and y coordinates to store user input efficiently.
Capture Coordinates in a Loop:
Use a loop to allow clicking on the image.
Each time the loop runs, it prompts the user to click on the image and stores the coordinates in the arrays.
After each click, a message is printed showing the stored coordinates and waits for a key press to continue to the next iteration.
Step 3: Running the Code
Open MATLAB and create a new script.
Copy and paste the code into the script.
Run the script, and click on the image four times at desired points.
Observe the console for feedback about each coordinate captured.
Conclusion
By following the steps above, you can efficiently extract X Y coordinates from an image using MATLAB. This technique is not only straightforward but also adaptable for various image-processing tasks. Feel free to modify the number of coordinates or tweak it to suit your needs! Happy coding!

Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: