MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

### Discover what MATLAB® can do for your career.

 Subject: Fractal Dimension From: Stelian Date: 8 Nov, 2004 18:18:08 Message: 1 of 9 Hi, Can anybody give me some hints for calculating the fractal dimension of a picture using Matlab? Thanks. Bye
 Subject: Fractal Dimension From: Per Sundqvist Date: 9 Nov, 2004 04:42:34 Message: 2 of 9 Stelian wrote: > > > Hi, > > Can anybody give me some hints for calculating the fractal > dimension > of a picture using Matlab? > > Thanks. > > Bye Recall the definition and you can do it by a for-loop. If you have a coastline, with aproximate fractal shape, saved as polygone vectors (x,y), you should calculate the circumference L of that object with different step-lengths h. Then by plotting log(L) vs. log(h) the slope should represent the fractal dimension (maby there was some constant also -google that).      Well it could happens (most-likely except for some easy figures like the Koch-star) that the fractal is not self-similar, i.e., the fractal dimension is not linear (look at the plot and you will see!). /Per
 Subject: Fractal Dimension Date: 9 Nov, 2004 06:15:49 Message: 3 of 9 Hi all, Inspiration can be found from the following links Higuchi Algorithm http://www.lyapunovpress.com/pdf/HiguchiFD.pdf    Katz Algorithm http://www.lyapunovpress.com/pdf/KatzFD.pdf     Petrosian Algorithm http://www.lyapunovpress.com/pdf/PetrosianFD.pdf    Sevick Algorithm http://www.lyapunovpress.com/pdf/SevickFD.pdf    Brahim > Hi, > > Can anybody give me some hints for calculating the fractal dimension > of a picture using Matlab? > > Thanks. > > Bye
 Subject: Fractal Dimension From: Stelian Date: 10 Nov, 2004 17:51:06 Message: 4 of 9 I understand what you are saying, but until then, how do I extract the coastline of the shape I'm interested in, from the picture, in order to aply the algorithm? thx Per Sundqvist wrote: > > > Stelian wrote: >> >> >> Hi, >> >> Can anybody give me some hints for calculating the fractal >> dimension >> of a picture using Matlab? >> >> Thanks. >> >> Bye > > Recall the definition and you can do it by a for-loop. > > If you have a coastline, with aproximate fractal shape, saved as > polygone vectors (x,y), you should calculate the circumference L of > that object with different step-lengths h. Then by plotting log(L) > vs. log(h) the slope should represent the fractal dimension (maby > there was some constant also -google that). > Well it could happens (most-likely except for some easy > figures > like the Koch-star) that the fractal is not self-similar, i.e., the > fractal dimension is not linear (look at the plot and you will > see!). > > /Per
 Subject: Fractal Dimension From: j Date: 10 Nov, 2004 21:19:34 Message: 5 of 9 hi Stelian, i wrote this code to trace the perimeter out a few years back:           j function perim= trimperim(name) if nargin<1, error('no file name');end; [origim,map]=imread(name); if origim(1,1)==1, origim=1-origim;end;         [h,w]=size(origim);   % trim         rows=sum(origim');         cols=sum(origim);          firstrow=min(find(rows>0));         dirlist=[0 1;1 0;0 -1;-1 0];         start=max(find(origim(firstrow,:)==1));         y=start;x=firstrow;dirj=4;         perim=zeros(h,w);         perim(x,y)=1;         startx=x;starty=y;count=0;         while x ~= startx | y ~= starty | count<4,         checkpos=[x y]+ dirlist(rem(dirj,4)+1,:);         if origim(checkpos(1),checkpos(2))==1,             x=checkpos(1);y=checkpos(2);             perim(x,y)=1;count=count+1;             dirj=rem(dirj,4)+1;         else            newpos=[x y]+ dirlist(dirj,:);            if origim(newpos(1),newpos(2))==1,               x=newpos(1);y=newpos(2);               perim(x,y)=1;count=count+1;               else               dirj=mod(dirj-2,4)+1;           end;        end;     end;
 Subject: Fractal Dimension From: Stelian Date: 15 Nov, 2004 17:11:01 Message: 6 of 9 Thanks for the source code, but it returns only zeros. i don't know what i'm doing wrong. What kind of picture should i use? I tried with grayscale pictures. Stelian j wrote: > > > hi Stelian, > i wrote this code to trace the perimeter out a few years back: > j > > function perim= trimperim(name) > > if nargin<1, error('no file name');end; > > [origim,map]=imread(name); > if origim(1,1)==1, origim=1-origim;end; > [h,w]=size(origim); > > % trim > rows=sum(origim'); > cols=sum(origim); > > firstrow=min(find(rows>0)); > dirlist=[0 1;1 0;0 -1;-1 0]; > start=max(find(origim(firstrow,:)==1)); > y=start;x=firstrow;dirj=4; > perim=zeros(h,w); > perim(x,y)=1; > startx=x;starty=y;count=0; > while x ~= startx | y ~= starty | count<4, > checkpos=[x y]+ dirlist(rem(dirj,4)+1,:); > if origim(checkpos(1),checkpos(2))==1, > x=checkpos(1);y=checkpos(2); > perim(x,y)=1;count=count+1; > dirj=rem(dirj,4)+1; > else > newpos=[x y]+ dirlist(dirj,:); > if origim(newpos(1),newpos(2))==1, > x=newpos(1);y=newpos(2); > perim(x,y)=1;count=count+1; > else > dirj=mod(dirj-2,4)+1; > end; > end; > end;
 Subject: Fractal Dimension From: j Date: 15 Nov, 2004 17:44:43 Message: 7 of 9 Stelian wrote: > What kind of picture should i use? 2 colours, all pixels should be either 1 or 0, if i recall correctly... you should go through the code line by line, to check it does what you need; i give no warranty that it works properly or gives the correct answers!
 Subject: Fractal Dimension From: Gagan Date: 15 Nov, 2004 19:55:41 Message: 8 of 9 j wrote: > > > Stelian wrote: >> What kind of picture should i use? > > 2 colours, all pixels should be either 1 or 0, if i recall > correctly... you should go through the code line by line, to check > it > does what you need; i give no warranty that it works properly or > gives the correct answers! If your image is pretty smooth in the interior of that perimeter then you can use gradient filters on that image (convolve image with the filter matrix) and then finding out where that gradient is greater than certain threshold should give you the perimeter. But I am making the assumption that you image intensity makes a sharp change at the perimeter. Gagan
 Subject: Fractal Dimension From: Surojit Ghosh Date: 16 Sep, 2008 06:09:03 Message: 9 of 9 please tell me how will I detect the following in MATLAB,        function perim= trimperim(name) ********************************** j wrote in message ... > hi Stelian, > i wrote this code to trace the perimeter out a few years back: > j > > function perim= trimperim(name) > > if nargin<1, error('no file name');end; > > [origim,map]=imread(name); > if origim(1,1)==1, origim=1-origim;end; > [h,w]=size(origim); > > % trim > rows=sum(origim'); > cols=sum(origim); > > firstrow=min(find(rows>0)); > dirlist=[0 1;1 0;0 -1;-1 0]; > start=max(find(origim(firstrow,:)==1)); > y=start;x=firstrow;dirj=4; > perim=zeros(h,w); > perim(x,y)=1; > startx=x;starty=y;count=0; > while x ~= startx | y ~= starty | count<4, > checkpos=[x y]+ dirlist(rem(dirj,4)+1,:); > if origim(checkpos(1),checkpos(2))==1, > x=checkpos(1);y=checkpos(2); > perim(x,y)=1;count=count+1; > dirj=rem(dirj,4)+1; > else > newpos=[x y]+ dirlist(dirj,:); > if origim(newpos(1),newpos(2))==1, > x=newpos(1);y=newpos(2); > perim(x,y)=1;count=count+1; > else > dirj=mod(dirj-2,4)+1; > end; > end; > end;