Reply by ravi shastri January 23, 20102010-01-23
Hai every one ,

this sis Ravi shastri iam doing my m.Tech project on image analysis to determine the particle size, i facing some errors in my code.here i want to do the calculations using matlab and that resut should be enter in Excel sheet.
please any on help me regrading. if some one helps me iam very greatful to them .

the code is

clear all; clc; close all;

str_path = '';
str_fname = 'DSC06076.JPG';
calib = [99 12.5];
% [pixels, mm] obtained manually measuring

%% Read image into matrix
img_orig = imread(strcat(str_path, str_fname));

%% Convert color image to grayscale
img_gray = rgb2gray(img_orig);

%% Determine gray level threshold
level = graythresh(img_gray)
img_bw = im2bw(img_gray, level); % Here particles are black
img_bw = 1 - img_bw; % Here particles are white and background is black

%% Fill holes
img_bw = imfill(img_bw, 'holes');

%% Remove border objects if any
img_bw = imclearborder(img_bw);

%% Identify individual particles and get features
% img_blob = bwconncomp(img_bw);
% img_bloblbl = labelmatrix(img_blob);
% img_blobrgb = label2rgb(img_bloblbl);

img_blob = bwlabeln(img_bw);
img_blobrgb = label2rgb(img_blob);
%blobs = regionprops(img_blob, 'Area', 'Perimeter', 'EquivDiameter');
blobs = regionprops(img_blob, 'Area', 'EquivDiameter');

display(['Found ', num2str(length(blobs)), ' particles']);

%% Statistics
pixel_areas = [blobs.Area];
pixel_eqvdia = [blobs.EquivDiameter];

dp = pixel_eqvdia .* calib(2) ./ calib(1);

%% Histograms
[n, xout] = hist(dp, 10);

cll_xls{1, 1} = 'dp [m]';
cll_xls{1, 2} = 'N';

for i = 1 : length(xout),
cll_xls{i + 1, 1} = xout(i);
cll_xls{i + 1, 2} = n(i);
end

%% Write to Excel
[pathstr, name, ext, versn] = fileparts(strcat(str_path, str_fname));
xlswrite(fullfile(pathstr, [name '.xls' versn]), cll_xls);

%% Display and plots
% Plotting Options
restype = '-r300';
imgtypepng = '-dpng';
imgextpng = 'png';
%%addition of diameter
figure;
subplot(2, 2, 1); imshow(img_orig); title('Original')
subplot(2, 2, 2); imshow(img_gray); title('Gray')
subplot(2, 2, 3); imshow(img_bw); title('Thresholded')
subplot(2, 2, 4); imshow(img_blobrgb); title('Particles')
print(imgtypepng, restype, strcat(str_fname, '_images.', imgextpng));

figure;
bar(xout, n);
print(imgtypepng, restype, strcat(str_fname, '_dist.', imgextpng));
%
%%( RCK Mods-begin
%
Ntot = length(blobs);
sumN = 0;
q0xi = 0;
dq0 = 0;
dq0dx = 0;
x3dq0dx = 0;
sumx3dq0dx = 0;
for j = 1 : length(xout),
sumN(j) = sumN(j) + n(j);
q0xi(j) = sumN(j) ./ Ntot;
if(j > 1) dq0(j) = q0xi(j)- q0xi(j-1);
if(j > 1) dq0dx(j) = 2 .* dq0(j) / (xout(j) - xout(j-1));
if(j > 1) x3dq0dx(j) = (xout(j) **3 .* dq0dx(j);
sumx3dq0dx = sumx3dq0dx + x3dq0dx(j);
end
for k = 1 : length(xout),
q3xdx(k) = x3dq0dx(k) ./ sumx3dq0dx;
end
)%
% RCK Mods-end
%

----------------------

K.Ravi shastri