# image processing - How to arrange this pixel address one by one?

I am doing map processing. I solved the maze and got the address of the turnings. Below is my result.

``(28,136)(122,136)(344,391)(548,493)(548,191)(344,191)(122,391)``

But the addresses are not in correct order. My expected output is:

``28 136122 136122 391344 391344 191548 191549 493``

MY program is below. I programmed to get direction also

``for(i=1:tblob)if (shape(i).order==1)map(i).cen=shape(i).cen;endendWhite=[255 255 255];i=1;order=1;left=0;right=0;up=0;down=0;left(1)=0;right(1)=0;up(1)=0;down(1)=0;left(2)=0;right(2)=0;up(2)=0;down(2)=0;left(3)=0;right(3)=0;up(3)=0;down(3)=0;left(4)=0;right(4)=0;up(4)=0;down(4)=0;left(5)=0;right(5)=0;up(5)=0;down(5)=0;left(6)=0;right(6)=0;up(6)=0;down(6)=0;left(7)=0;right(7)=0;up(7)=0;down(7)=0;left(8)=0;right(8)=0;up(8)=0;down(8)=0;x=map(i).cen(1,:);y=map(i).cen(2,:);for(z=1:100)xi=x+1;xj=x-1;yi=y+1;yj=y-1;colorvalxi=color(y,xi,RGB);colorvalxicolorvalxj=color(y,xj,RGB);colorvalxjcolorvalyi=color(yi,x,RGB);colorvalyicolorvalyj=color(yj,x,RGB);colorvalyjif(i>1)s=i-1;elses=1;endif (left(s)==0)if(colorvalxi==White)n=1;endelseif (right(s)==0)if(colorvalxj==White)n=2;endelseif(up(s)==0)if (colorvalyi==White)n=3;endelseif(down(s)==0)if(colorvalyj==White)n=4;endelsebreak;endendendendswitch(n)case 1 %RIGHTfor(ks=1:1000)color_val=color(y,x,RGB);if(color_val==White)x=x+1;elseright(i)=1;instruction(i)=1;i=i+1;x=x-1;map(i).cen(1,1)=x;map(i).cen(2,1)=y;break;endendcase 2 %LEFTfor(ks=1:1000)color_val==color(y,x,RGB)if(color_val==White)x=x-1;elseleft(i)=1;instruction(i)=2;i=i+1;x=x+1;map(i).cen(1,1)=x;map(i).cen(2,1)=y;break;endendcase 3 %DOWNfor(ks=1:1000)color_val=color(y,x,RGB);if(color_val==White)y=y+1;elsedown(i)=1;instruction(i)=3;i=i+1;y=y-1;map(i).cen(1,1)=x;map(i).cen(2,1)=y;break;endendcase 4 %UPWARDfor(ks=1:1000)color_val=color(y,x,RGB);if(color_val==White)y=y-1;elseup(i)=1;instruction(i)=4;i=i+1;y=y-1;map(i).cen(1,1)=x;map(i).cen(2,1)=y;break;endendendend``