Simple Matlab Code for Generatig Isodipole Textures

Jonathan Victor: jdvicto@med.cornell.edu


introduction to isodipole textures
examples of the textures
references on isodipole textures

Matlab code for Isodipole Textures

Two methods are shown: a simple but slow way, and a fast vectorized method % evenodd_demo.m % demonstrates construction of even and odd textures, as well as decorrelated versions % rows=input('number of rows (e.g., 20):'); cols=input('number of columns (e.g., 30):'); fprop=input('propagated decorrelation fraction (0=even, 1=odd, 0.5=random):'); fspor=input('sporadic decorrelation fraction (0=even, 0.5=random):'); % % the straightforward but really slow way % tic; tex1=zeros(rows,cols); tex1(1,:)=(rand(1,cols)>0.5); %random first row tex1(:,1)=(rand(rows,1)>0.5); %random first column % %do the iteration, with propagated decorrelation % for ir=2:rows for ic=2:cols if (rand(1,1)<fprop) bump=1; else bump=0; end tex1(ir,ic)=mod(bump+tex1(ir,ic-1)+tex1(ir-1,ic)+tex1(ir-1,ic-1),2); end end % %add sporadic decorrelation % for ir=1:rows for ic=1:cols if (rand(1,1)<fspor) tex1(ir,ic)=1-tex1(ir,ic); end end end time1=toc; disp(sprintf(' straightforward way: %6.2f',time1)); figure;imagesc(tex1,[0 1]);colormap gray; % % the dense but fast way % tic; tex2=repmat((rand(1,cols)>0.5),rows,1)+repmat(rand(rows,1)>0.5,1,cols); %even texture tex2=mod(tex2+cumsum(cumsum((rand(rows,cols)<fprop)),2)+(rand(rows,cols)<fspor),2); %add decorrelation time2=toc; disp(sprintf(' fast way: %6.2f',time2)); figure;imagesc(tex2,[0 1]);colormap gray; %