Convert im2double array to function

I apologize in advance for my poor inability to explain code, though I'll do my best to say how I went about each step.
To test a proof-of-concept, I went into Paint and generated an image of a black squiggly on a white background. I played around with the image ('test.jpg') as follows:
I=imread('test.jpg'); %loaded the image%
t=50;
I(find(I<=t))=49;
I(find(I>t))=0;
t=48;
I(find(I>t))=255; %%All of this collectively made an array of the image, and converted all values for the white background to 0 and the black squiggly to 255%%
im2double(I); %this made all of the 255's into 1's, meaning the entire array is now 0's and 1's. Looking at the array output, it's exactly what I see; the image was 28x25, and the array is 28x25 with 1's in the cells where the squiggly line was.%
final product example, if I had originally had an X-shaped squiggly image (12x10) and gone through the above steps:
000000000000
010000000010
001000000100
000100001000
000010010000
000001100000
000010010000
000100001000
001000000100
010000000010
What I want to do, though, is make it so that my squiggly of 1's in the array can be converted into a graphable function in Matlab. I'm doing all of this as a way to convert the squiggly found in the image into a function whose derivatives can be determined. My guess is that, at this point, I only need to find the indices (or locations) of these 1's in my 28x25 grid (a sparse matrix given how much white background 0's there are) and somehow map these coordinates onto a plane. But, I have no idea how to do this. I played around with the find functions and [row,col] find functions, but don't know if I was achieving anything or what to do with it. Does anyone have any advice on this?
Thanks!
-Steve

Answers (2)

Try something like this
[y x] = find(yourImage);
scatter(x, y);
If you want lines along your "X" then you're going to have to have it be two curves, or one with a NaN in there so that the one leg of the X is not attached to the other. And you're going to have to figure out how to do the splitting up. That's not easy. How would one know if it's a V and a ^ point-to-point, or if it's an X, or if it's >< (two angle brackets).
The first part of what you are doing can be done by
I = imread('test.jpg');
newI = I <= 50;
The part about finding the function, though:
You have two lines joining each other, and you have multiple Y for each X. These two facts together imply that the function would have to be a function of at least two variables. Was that your intention ? Also as you cannot tell whether the two lines just "kiss" or cross each other, there would be multiple "minimal" solutions, and so multiple possibilities for the derivatives.

Asked:

on 12 Dec 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!