Translating curves in paint to matlab

In summary, you can read an image into MATLAB using the imread command. Check the docs for details and examples.
  • #1
tom.coyne
8
0
Hi,
I am currently using MATLAB to do some work on simple closed curves in the plane. In order to make this work quite general I have opted to use a matrix which stores (x,y) coordinates of points on my curve (rather than use a function).

I want to feed some interesting curves into my code but currently this relies on me finding a parametric representation and this tends to mean they are not so exciting.

I would like to be able to draw a closed curve in paint or something and then translate that into a set of coordinates which I can store as a matrix in matlab.

Does anyone know how I might go about this??

Thanks,
Tom
 
Last edited:
Physics news on Phys.org
  • #2
You can read an image into MATLAB using the imread command. Check the docs for details and examples.
 
  • #3
Thanks for the tip, however after spending some time trawling the help pages, I'm still not sure how to proceed.

So at the moment I have drawn a circle in paint and saved it as a greyscale bmp. imread will then turn this into a matrix of 1's and 0's. I take it these refer to the pixels a 1 meaning there is something drawn there and a 0 meaning nothing drawn.

How can I convert this matrix into an n x 2 matrix which just describes the x and y coordinate of each point on the curve? Am I going to have to run some kind of for loop?

Thanks,
Tom
 
  • #4
Yes, just step through the matrix and whenever the element==1 you store that position (indices) in your nx2 matrix.
 
  • #5
How am I going to make sure that the points remain next to each other?

I can see that it would be easy for a line, but it gets more complex for a circle. Then my aim is to make quite complex snake like shapes. Since I will be integrating this data, it would be best if the data points which were close in the picture remained close in the nx2 matrix.

The good thing is the data points I end up with don't have to accurately represent the curve I drew in paint, so would I be able to interpolate the 'messed up' data to make a smooth curve?

Also, more fundamentally, I think I must be making a mistake somewhere, here is what I got for my circle:

A = imread('circle.bmp', 'bmp');

Then I run this:

function [x,y] = coordinate_generator(A)
z = size(A);
k = 1;
for i = 1:z(2)
for j = 1:z(1)
if A(j,i)==0
x(k) = i;
y(k) = j;
k = k+1;
end
end
end

Attached is the start picture and the picture I got from plotting [x,y]

What am I doing wrong?
 

Attachments

  • circle.bmp
    27.1 KB · Views: 611
  • plotted data.jpg
    plotted data.jpg
    21.5 KB · Views: 467

1. How can I translate a curve in paint to MATLAB?

To translate a curve in paint to MATLAB, you will need to first save the curve as an image file. Then, you can use the "imread" function in MATLAB to read the image file and convert it into an array of pixel values. From there, you can manipulate the array to create a curve in MATLAB.

2. Can I translate a curve in paint to MATLAB without using an image file?

Yes, it is possible to translate a curve in paint to MATLAB without using an image file. This can be done by manually inputting the coordinates of the curve into MATLAB and using the "plot" function to create the curve. However, using an image file may provide a more accurate representation of the curve.

3. How do I ensure the accuracy of the translated curve in MATLAB?

To ensure the accuracy of the translated curve in MATLAB, it is important to carefully save the curve as an image file and to use appropriate functions and techniques to read and manipulate the image file in MATLAB. It may also be helpful to check the accuracy of the translated curve by comparing it to the original curve in paint.

4. What are the benefits of translating a curve in paint to MATLAB?

Translating a curve in paint to MATLAB allows for more precise manipulation and analysis of the curve. This can be useful for scientific or mathematical purposes, as MATLAB offers a wide range of tools and functions for data analysis and visualization.

5. Can I translate a curve in paint to MATLAB if I am not familiar with either program?

It may be more challenging to translate a curve in paint to MATLAB if you are not familiar with either program. However, there are many online resources and tutorials available to help guide you through the process. It may also be helpful to consult with a colleague or seek assistance from a technical support team.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
32
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
11K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
Back
Top