|
"Aleks " <di.elijen@gmail.com> wrote in message <h1607a$nb2$1@fred.mathworks.com>...
> Hi!
>
> I have a 5x5 pixel image, and I randomlly choose two pixels that I would like to connect. I want to generate all possible routes between these two pixels. I used this file from File Exchange:
> http://www.mathworks.com/matlabcentral/fileexchange/12724
> to generate all the possible combinations of a set of elements, but I ran out of memory.
>
> I would appreciate your help on this.
> Aleks
OK. I guess you have to limit the route to go backward, otherwise you are infinity number of solutions, even for two pixels very close.
First, just consider a simple case where route is horizontal or vertical (go diagonal is not allowed). Let's call (dx,dy) the separation between 2 pixels.
Take a route, it crosses the vertical axis in (dy+1) vertical positions. Le's call x(k) is how many pixels the route go horizontally in the vertical position #k. The array x() can be 0 to dx, and sum(x)=dx.
That mean a route is coded by
x() of dimension dy+1, sum(x)==dx.
How to generate all the routes, i.e., x as above? Using my file on FEX
http://www.mathworks.com/matlabcentral/fileexchange/17818
This File returns also the number of solutions. For example for two pixels separate by dx=2, dy=2
>> dx=2; dy=2; nroute=allVL1(dy+1,dx,'==',NaN)
nroute =
6
>> x=allVL1(dy+1,dx,'==') %
x =
0 0 2 % up 2 + right 2
0 1 1 % up 1 + right 1 + up 1 + right 1
0 2 0 % up 1 + right 2 + up 1
1 0 1 % right 1 + up 2 + right 1
1 1 0 % right 1 + up 1 + right 1 + up 1
2 0 0 + right 2 + up 2
>>
It is possible to derive a diagonal routes from the above. I let you to have fun with it.
Bruno
|