File Exchange

image thumbnail

Fractal Dimension

version 1.0.0.0 (2.43 KB) by

Generating a pixel- by pixel fractal dimension image using box counting algorithm

25 Downloads

Updated

View License

The fractal dimension (FD) image is generated by considering each pixel in the original CT image as a single fractal dimension estimated from its 7x7 neighbours. The FD generated image remarkably enhances the tissue texture, and the internal subtle structures become more obvious as compared to the original CT image. This could help the physician's eyes in better delineating the tumour from the surrounding normal tissue; furthermore, the mean Fractal Dimension value of the tumour region of interest can give an indication of tumour aggressiveness. See the following reference: O. S. Al-Kadi and D. Watson, “Texture Analysis of Aggressive and non-Aggressive Lung Tumor CE CT Images,” IEEE Transactions on Biomedical Engineering, vol. 55, pp. 1822-1830, 2008.

Comments and Ratings (10)

Omar Al-Kadi

Thanks Rawan.

How to apply the algorithm to a 1024x1024 image ?

rawan

rawan (view profile)

rawan

rawan (view profile)

Thank you very much for this code Dr.Omar.
I have an optimization to your code, it is as follows:

% Fractal dimension (FD) calculation using differential box counting algorithm.
% Author: Omar S. Al-Kadi (e-mail: o.al-kadi@sussex.ac.uk; o.alkadi@ju.edu.jo)
% Optimized Version By: Rawan I.Zaghloul. University of Jordan
%----------------------------------------------------------------------------

clc;
clear all;
close all;
%*---------- Reading image(s) with a specific format -----------*%
[filename, pathname, filterindex] = uigetfile( ...
{ '*.dcm','DICOM (*.dcm)'; ...
'*.jpg','JPEG (*.jpg)'; ...
'*.bmp','Windows Bitmap (*.bmp)'; ...
'*.fig','Figures (*.fig)'; ...
'*.*', 'All Files (*.*)'}, ...
'Choose image(s) to be processed', ...
'MultiSelect', 'on');

if filterindex==0, break;end

filename=cellstr(filename);
rem=filename;
while true
[token, rem] = strtok(rem,'.');
if isempty(char(rem)), break; end
end

num=numel(token);
h = waitbar(0,'Loading selected image(s) in progress...');
for i= 1:num
switch(lower(char(token(i))))
case 'dcm'
J= dicomread(horzcat(pathname,char(filename(i))));
if ndims(J) >3
Js=squeeze(J);
Js1=Js(:,:,1);
Js2=Js(:,:,2);
Js3=Js(:,:,3);
Jc=cat(3,Js1,Js2,Js3);
Ig=rgb2gray(Jc);
I{i}= Ig;
else I{i}= J; end
waitbar(i/num)
case {'fig','m'}
I{i}= load(horzcat(pathname,char(filename(i))));
waitbar(i/num)
case {'jpg','jpeg','bmp','png','tiff','tif','gif'}
J= imread(horzcat(pathname,char(filename(i))));
if ndims(J) >2
I{i}= rgb2gray(J);
else I{i}= J; end
waitbar(i/num)
otherwise
I{i}= load(horzcat(pathname,char(filename(i))));
waitbar(i/num)
end
end
close(h);

for j=1:num
[M,N]= size(I{j});
iname = char(strtok(filename(j), '.'));

%------- performing non-linear filtering on a varying size pixel block -------%
h = waitbar(0,'Performing 3-D Box Counting...');
cc = 1;
for r=7:-1:2
rc = @(x) floor(((max(x)-min(x))/r))+ 1; % non-linear filter
F= colfilt(I{j}, [r r],'sliding', rc);
B{cc}= log(double(F * (49/(r^2))));
waitbar(r/6)
cc = cc+1;
end
close(h)

i=log(2:7); % Normalised scale range vector
%------- computing the slope using linear regression -------%
Nxx=dot(i,i)-(sum(i)^2)/6;
for aa=2:M*N
i(:,:,aa)= i(:,:,1);
end

h = waitbar(0,'Transforming to FD...');
Z = cellfun(@(x)reshape(x,1,1,[]),B,'un',0);
fd = cell2mat(Z);
Nxy=dot(i,fd)-(sum(i).*sum(fd))./size(fd,2);
FD{1}= (Nxy/Nxx);
F = reshape(FD{1},M,N);
close(h)
end

%*----------- selecting a Region of Interest & finding corresponding average FD and Lacunarity ------*%
figure,[S, c, r]= roipoly(mat2gray(F));
for j=1:size(I,2)
ROI= FD{j}(find(S==1));close;
FDavg(j)= sum(ROI)/ numel(ROI) % Average FD for selected area
FDsd(j)= std(ROI) % Standard deviation of FD for selected area
FDlac(j)= ((sum(ROI.^2)/(length(ROI)))./((sum(ROI)/(length(ROI)))^2))-1
% Lacunarity for selected area
end

Can you tell me how to specifically calculate fractal surface dimension by 3D box counting method?

Abhijit

Only concern is that this runs slow. Can you recommend any optimization?

Faraz

Faraz (view profile)

Thanks for posting it (y)

Omar Al-Kadi

Thank you Mohammad for your kind comment. Yes there are many ways to compute the FD other than the Box Counting method, such as the fractal Brownian motion by estimating the Hurst index, or via the signals' power spectrum, or using the autocorrelation function. All of these FD estimation approaches attempt to quantify the roughness of the 2D signal surface.

Mohammad

Thanks for sharing, you did a nice job.
I have a question. Is there any other way to generate the slope (FD image) than linear regression of Nd and r?

MATLAB Release Compatibility
Created with R2008a
Compatible with any release
Platform Compatibility
Windows macOS Linux

MATLAB Online Live Editor Challenge

Win cash prizes and have your live script featured on our website

Learn more

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video