Count Grain Number from Input Image

5 views (last 30 days)
Parth Desai
Parth Desai on 10 Sep 2018
Answered: AMAR P on 10 Oct 2018
Hello,
How can I calculate number of grains from metal image ? Based on grain number I want to find out input image is of which metal. Should I use line and point-sampled intercept length methods for finding number of grains.

Answers (1)

AMAR P
AMAR P on 10 Oct 2018
hi I hope you have worked out the problem. Here is my take on a problem. Might help others in coming years.
% file:
% Author: AMAR P.
% Version: V1
clc
clearvars;
close all;
MainImg = imread('Temp.bmp');
% Convert to GrayScale Image [To perform histeq]
GrayImg = rgb2gray(MainImg);
% Intensity transformation
GrayImg = histeq(GrayImg);
% Convert to Binary Image
BinImg = im2bw(GrayImg);
%Get Resion props
GrainProps = regionprops('table', BinImg,'Centroid');
% Get No of Grains in the image
NoOfGrains = numel(GrainProps);
%Read All Centers into Array
GrainCenters = GrainProps.Centroid;
% Mark Grains at Center.
figure(1);
imshow(BinImg);
hold on;
text(GrainCenters(:,1), GrainCenters(:,2),'*','Color','r');
hold off
fprintf('\nNo. Of Grains found in the Image = %d\n', NoOfGrains);
_ No. Of Grains found in the Image = 610_

Products


Release

R2014a

Community Treasure Hunt

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

Start Hunting!