Processing of data after image analysis, overlaying the distribution

3 views (last 30 days)
Hallo everyone,
I have a question about processing data of image analysis.
I have 100 images to analysis, i would like to do the distribution of its properties, like area, perimeter, I have already use the code here to run all the images from one folder automatically. now I could save all the datas of all the processing images individually and overlaying its distribution and save it. my code is as following,
clc; % Clear the command window.
close all;
% Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
fontSize = 10;
% Specify the folder where the files live.
myFolder = 'C:\Users\images';
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.bmp'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
% Array to store all the areas from all the images.
allAreas=[];
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Read original image and store in matrix D
grayImage = imread(fullFileName);
grayImage=im2gray(grayImage);
[rows, columns, numberOfColorChannels] = size(grayImage)
% Filtering image by median filter to remove noise and retain the image details
MJ=medfilt2(grayImage,[3 3]); % Use median filter to remove noise and retain image details
% Generate binarized image
Threshold=graythresh(MJ)
DBinarized=~imbinarize(MJ,Threshold);
% Fill the holes of particles
DFill=imfill(DBinarized,'holes');
% Remove small objects from binary image
DRemove=bwareaopen(DFill,50);
% a) Count number of agglomerates
[L,Num]=bwlabel(DRemove,8);
disp('Number of aggregates')
disp(Num)
% Let's assign each blob a different color to visually show the user the distinct blobs.
coloredLabels = label2rgb (L, 'hsv', 'k', 'shuffle');
Characteristicdiameters=regionprops(DRemove,'Orientation','MajorAxisLength','MinorAxisLength','Eccentricity','Area','Perimeter');
Areas=[Characteristicdiameters.Area]
Perimeters=[Characteristicdiameters.Perimeter]
Eccentricity=[Characteristicdiameters.Eccentricity]
% Put all the properties in each array individually
allAreas = [allAreas, Areas];
subplot(2,4,1),imshow(grayImage),title('gray Image', 'FontSize', fontSize);
subplot(2,4,2),imshow(MJ),title("image after filtering");
subplot(2,4,3),imshow(DBinarized),title('Binarized Image', 'FontSize', fontSize);
subplot(2,4,4),imshow(DFill),title('Image after filling holes', 'FontSize', fontSize);
subplot(2,4,5),imshow(DRemove),title('Image without samll objects', 'FontSize', fontSize);
figure
drawnow; % Force display to update immediately.
end
subplot(5,5,1);
histogram(allAreas);
xlabel('Area of Agglomerate'); ylabel('Count');
title('Areas of agglomerate histogram')
when I run these code, the area distribution shows all the objects in all the images, however i would like to do is, for example, first image is analysed, and i get the first area distirbution of objects in the first image and save it, then second image is analysed, then i get second distribution of objects of second image,the second ditribution is added to the first distribution show it and save it, then third image is analysed and get third distribution of objects in the third image, and add it to the distribution which the first and second distribution already combined.
just to make it clearly, so i manually make this distirbution, from left to right, i get first dirstribution of objects in he first image, then i get second distribution of objects in second image, then combine first distribution 1 and 2, continue, get third distribution of objects in the third image, then add this to the combination distribution of 1 and 2.
Another question is if i analysis all the objects from all the images, if i would like to choose some objects from all the images randomly and do this kind of distribution again, what should I do.
thanks in advance.
JL

Answers (1)

Image Analyst
Image Analyst on 18 Jul 2023
Edited: Image Analyst on 19 Jul 2023
In your loop, you need to add a plot of the histogram of just the areas of just the areas of the current image. so before the loop, make a figure for it in addition to the one for your intermediate images.
hAreas = figure;
hImages = figure;
plotRows = ceil(sqrt(numel(theFiles)))
for k = 1 : length(theFiles)
% Analysis code, then.....
% Concatenate the areas for this one image onto a growing array
% of all the blobs areas for all images.
allAreas = [allAreas, Areas];
% Switch to figure for the distribution of the areas.
figure(hAreas);
subplot(plotRows, plotRows, k);
histogram(Areas); % Display histogram of just this one image, not all of them.
grid on;
drawnow; % Force display to update immediately.
% Now switch to figure for the intermediate images.
figure(hImages);
subplot(2,4,1),imshow(grayImage),title('gray Image', 'FontSize', fontSize);
subplot(2,4,2),imshow(MJ),title("image after filtering");
subplot(2,4,3),imshow(DBinarized),title('Binarized Image', 'FontSize', fontSize);
subplot(2,4,4),imshow(DFill),title('Image after filling holes', 'FontSize', fontSize);
subplot(2,4,5),imshow(DRemove),title('Image without samll objects', 'FontSize', fontSize);
drawnow; % Force display to update immediately.
end
% Now plot the histogram of areas of all blobs in all images.
hAllHists = figure;
histogram(allAreas);
grid on;
title('Histogram of all blobs in all images')
  2 Comments
Jialin Men
Jialin Men on 19 Jul 2023
Hallo Image Analyst,
Thanks so much for your genious help.
I try to use the code you write to me, i add something in your code.
hAreas = figure;
hImages = figure;
plotRows = ceil(sqrt(numel(theFiles)))
Allareas=[]% here i add it, otherweise code does not work,
% Now switch to figure for the intermediate images.
figure(hImage); %here show unrecognized function or variable hImage
subplot(2,4,1),imshow(grayImage),title('gray Image', 'FontSize', fontSize);
subplot(2,4,2),imshow(MJ),title("image after filtering");
subplot(2,4,3),imshow(DBinarized),title('Binarized Image', 'FontSize', fontSize);
subplot(2,4,4),imshow(DFill),title('Image after filling holes', 'FontSize', fontSize);
subplot(2,4,5),imshow(DRemove),title('Image without samll objects', 'FontSize', fontSize);
drawnow; % Force display to update immediately.
end
% Now plot the histogram of areas of all blobs in all images.
%Here I would like to show the distributions like I said, one step by one step, now i have get each area distribution of objects from image, but i want not show all directly, but step by step, second area distrbution plus first area distribution, show it, dann third area distribution add on it, show the third area distribution.
hAllHists = figure;
histogram(allAreas);
grid on;
title('Histogram of all blobs in all images')
Thanks again
JL

Sign in to comment.

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!