Measurement of properties from Tiff image
11 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
回答 (2 件)
Benjamin Thompson
2022 年 11 月 21 日
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.
0 件のコメント
Image Analyst
2022 年 11 月 21 日
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);
参考
カテゴリ
Help Center および File Exchange で Image Processing and Computer Vision についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!