Measurement of properties from Tiff image

11 vues (au cours des 30 derniers jours)
Huseyin Hizli
Huseyin Hizli le 21 Nov 2022
Commenté : Huseyin Hizli le 21 Nov 2022
Hello,
I have an image of a microstructure and I want to calculate some features like volume fraction, length, width. I have tried to calculate them by binarising the image and then regionprops but I could not manage to get what i want. I have upload an sample image here and basically, i want to calculate volume fractions, length and width of the features. First of all, I want to calculate the volume fraction, length and width of precipitates encircled by blue circle. They are always black in colour and needle like. Then, I need to calulate the same for red circled region, where the colour is grayish. This is one of the phase (alpha) and always appears in grayish. The rest bright grayish area is the second phase (beta) and I only need its volume fraction and width. I know the image is too noisy and if I can remove the background noise, it will be good too.
So my question is if it is possible to calculate the volume fractions, length and width of three features with MATLAB. I am so new to MATLAB and so my coding skills are not excellent.

Réponses (2)

Benjamin Thompson
Benjamin Thompson le 21 Nov 2022
If you are using the Image Processing Toolbox then you are probably trying to use the regionprops function with the "Area" property output enabled. But this first requires that you have labeled the image or identified the groups of pixels that are part of your features of interest. That looks like a hard problem.

Image Analyst
Image Analyst le 21 Nov 2022
Here's a start:
% Demo 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;
markerSize = 40;
%--------------------------------------------------------------------------------------------------------
% READ IN IMAGE
folder = [];
baseFileName = 'core 2.tif';
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)
%--------------------------------------------------------------------------------------------------------
% Crop off black bottom graphics area.
grayImage = grayImage(1:1920, :);
%--------------------------------------------------------------------------------------------------------
% Display the image.
subplot(2, 3, 1);
imshow(grayImage);
impixelinfo;
axis('on', 'image');
title('Original Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
fprintf('It is not really gray scale like we expected - it is color\n');
% Extract the blue channel.
grayImage = grayImage(:, :, 3);
end
% Update 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)
% Maximize window.
g = gcf;
g.WindowState = 'maximized';
drawnow;
%--------------------------------------------------------------------------------------------------------
% Do a median filter to remove noise
windowSize = 5;
grayImage = medfilt2(grayImage, [windowSize, windowSize]);
subplot(2, 3, 3);
imshow(grayImage);
impixelinfo;
axis('on', 'image');
title('Median Filtered Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
%--------------------------------------------------------------------------------------------------------
% Show the histogram
subplot(2, 3, 2);
imhist(grayImage);
title('Histogram of Original Image', 'FontSize', fontSize, 'Interpreter', 'None');
grid on;
%--------------------------------------------------------------------------------------------------------
% Interactively and visually set a threshold on a gray scale image.
% https://www.mathworks.com/matlabcentral/fileexchange/29372-thresholding-an-image?s_tid=srchtitle
lowThreshold = 0;
highThreshold = 26;
% [lowThreshold, highThreshold] = threshold(lowThreshold, highThreshold, grayImage)
%--------------------------------------------------------------------------------------------------------
% Create a mask
mask = grayImage >= lowThreshold & grayImage <= highThreshold;
subplot(2,3, 4);
imshow(mask, []);
impixelinfo;
axis('on', 'image');
title('Mask', 'FontSize', fontSize, 'Interpreter', 'None');
%--------------------------------------------------------------------------------------------------------
% Measure blob sizes
props = regionprops(mask, 'Area');
allAreas = [sort([props.Area], 'descend')]
subplot(2,3, 5);
histogram(allAreas);
title('Histogram of blob areas', 'FontSize', fontSize, 'Interpreter', 'None');
grid on;
% Determine smallest allowable by examining the image then filter them out.
smallestAllowableArea = 400;
mask = bwareafilt(mask, [smallestAllowableArea, inf]);
props = regionprops(mask, 'Area');
allAreas = [sort([props.Area], 'descend')]
subplot(2,3, 5);
imshow(mask, []);
impixelinfo;
axis('on', 'image');
title('Cleaned Mask', 'FontSize', fontSize, 'Interpreter', 'None');
subplot(2,3, 6);
histogram(allAreas);
grid on;
title('Histogram of blob areas', 'FontSize', fontSize, 'Interpreter', 'None');
%--------------------------------------------------------------------------------------------------------
% Label each blob with 8-connectivity, so we can make measurements of it
[labeledImage, numberOfBlobs] = bwlabel(mask, 8);
% Apply a variety of pseudo-colors to the regions.
coloredLabelsImage = label2rgb (labeledImage, 'hsv', 'k', 'shuffle');
% Display the pseudo-colored image.
imshow(coloredLabelsImage);
% Get all the blob properties. Can only pass in originalImage in version R2008a and later.
props = regionprops(labeledImage, grayImage, 'all');
numberOfBlobs = size(props, 1);
  1 commentaire
Huseyin Hizli
Huseyin Hizli le 21 Nov 2022
wow this looks impressive. I have denoised the image but I could not go this far. I have two questions now. First, how can I make Matlab to measure dimeansions and area of the coloured features? Second question is about the other features that I have circled. Now I can distinguish the black features from microstructure, but I also want to distinguish gray and bright gray regions so that I can measure their dimensions and areas.
Thank you

Connectez-vous pour commenter.

Catégories

En savoir plus sur Image Processing and Computer Vision dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by