Measure the spreading length using image analysis.

In the attached image there are three figures where the spreading length is changing. How can I measure the spreading length of a set of images?

 채택된 답변

Image Analyst
Image Analyst 2020년 6월 23일
Try this:
% By Image Analyst
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.
format long g;
format compact;
fontSize = 22;
%--------------------------------------------------------------------------------------------------------
% READ IN IMAGE
folder = pwd;
baseFileName = 'spreading.jpeg';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
grayImage = rgb2gray(grayImage);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
% grayImage = grayImage(:, :, 2); % Take green channel.
end
subplot(2, 2, 1);
imshow(grayImage, []);
impixelinfo;
title('Original Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
hFig = gcf;
hFig.WindowState = 'maximized'; % May not work in earlier versions of MATLAB.
drawnow;
%--------------------------------------------------------------------------------------------------------
% SEGMENTATION OF IMAGE
% Get a binary image
binaryImage = ~imbinarize(grayImage);
% Extract 3 largest blobs only.
binaryImage = bwareafilt(binaryImage, 3);
subplot(2, 2, 2);
imshow(binaryImage, []);
impixelinfo;
title('Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
hFig = gcf;
hFig.WindowState = 'maximized'; % May not work in earlier versions of MATLAB.
drawnow;
% Get the bounding boxes
props = regionprops(binaryImage, 'BoundingBox');
allBB = vertcat(props.BoundingBox)
% Find out which is on top.
y = allBB(:, 2)
[sortedY, sortOrder] = sort(y, 'ascend')
% Sort props the same way.
allBB = allBB(sortOrder, :)
allWidths = allBB(:, 3)
allHeights = allBB(:, 4)
subplot(2, 2, 3);
bar(allWidths);
grid on;
title('Blob Widths', 'FontSize', fontSize, 'Interpreter', 'None');
xlabel('Blob Number', 'FontSize', fontSize, 'Interpreter', 'None');
ylabel('Width', 'FontSize', fontSize, 'Interpreter', 'None');
subplot(2, 2, 4);
bar(allHeights);
grid on;
title('Blob Heights', 'FontSize', fontSize, 'Interpreter', 'None');
xlabel('Blob Number', 'FontSize', fontSize, 'Interpreter', 'None');
ylabel('Height', 'FontSize', fontSize, 'Interpreter', 'None');

댓글 수: 3

Hello, I have a similar type of problem. I have a series of images of droplet impacting on another droplet. The images are in RGB color but I converted to grayscale and binarizeit it. Now how do I measure the distance between the two ends from the binarized image supposing that I know a scale of '78 pixels/mm' in the image. From the above code I couldnot figure out the calculation part. Also how to automate it for a large number of image files where the spread increases continously.
clc;clear;
folder = 'I:\converted images\0.5\0.5 2 mm offset';
baseFileName = '0.5 cmc 2mm off0001.tif';
fullFileName = fullfile(folder, baseFileName);
[grayImage,map] = imread(fullFileName);
%impixelinfo;
grayImage = rgb2gray(grayImage);
%[img,map] = imread(fname,k)
imshow(grayImage,map)
binaryImage = ~imbinarize(grayImage);
imshow(binaryImage)
RGB to gray binary
@naygarp, see the FAQ:
Start your own question if you need more help. And attach your images and code.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 6월 21일
Two ways: I am considering the pixel distance length based on spaial coordinates (Not the general scale length like mm or cm)
Option 1: Image Segmenattion
  1. Do Image segmentation and find the ROI (Dark part of the images)
  2. Please do some sort of morpho operations to enure having single blob only (Dark region)
  3. Find the distance between farthermost two black pixels
Oprion 2: Using ginput
data=imread('image9.jpeg');
imshow(data);
[x y]=ginput(6);
x=round(x);
y=round(y);
image1_dist=sqrt((x(2)^2-x(1)^2)+y(2)^2-y(1)^2)
image2_dist=sqrt((x(4)^2-x(3)^2)+y(4)^2-y(3)^2)
image3_dist=sqrt((x(6)^2-x(5)^2)+y(6)^2-y(5)^2)
Command Window:
image1_dist =
300.3681
image2_dist =
331.2990
image3_dist =
337.3603
>>

댓글 수: 4

mathru
mathru 2020년 6월 21일
편집: mathru 2020년 6월 21일
Thank you for your reply. One thing is that, here I have put three different images in one image. In general I have such 2000 individual images where spreading lengths are changing in every images. I am looking for a code that can generate the length of every image in file. See the attached images for example.
As images number are quite high, then it must be automated to get the distance, see option 1
mathru
mathru 2020년 6월 21일
It would be easy for me if you can give me a demonstration of that.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

질문:

2020년 6월 21일

댓글:

2021년 6월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by