%create base image L=1024; baseIm=zeros(L,L,'uint8'); locations=[]; %start looping i_max = 7 for i=1:i_max; %create blank image (black) bImg=zeros(L,L,'uint8'); %create random locations matrix for j=1:4^(i+1); %number of dots to be generated locations(j,1)=randi([1 L]); locations(j,2)=randi([1 L]); bImg(locations(j,1),locations(j,2))=255*i/24; %add dots of size 1 at random locations end size=round(512/(2^(2*i))); %size of dots se = offsetstrel('ball',size,size); %dilatation size dilatedIm = imdilate(bImg,se); %dilate to size %modImg=imnoise(dilatedIm,'salt & pepper'); %add salt&pepper modImg=imgaussfilt(dilatedIm,(1.7-0.2*i)); %imgaussfilt baseIm=(baseIm+modImg); %add to base image end Min=min(min(baseIm)); normIm=(baseIm-Min)*(255/(255-Min)); whiteBG2=imcomplement(normIm); imshow(whiteBG2); clear dilatedIm i j L locations Min modImg se size