0% found this document useful (0 votes)
15 views2 pages

Question1 Rice

The document outlines a MATLAB script for analyzing rice grains in an image. It includes steps for loading and preprocessing the image, binarizing it, finding connected components, and calculating statistics on the detected grains. A total of 95 rice grains were identified in the analysis.

Uploaded by

ahmadchughtai21
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

Question1 Rice

The document outlines a MATLAB script for analyzing rice grains in an image. It includes steps for loading and preprocessing the image, binarizing it, finding connected components, and calculating statistics on the detected grains. A total of 95 rice grains were identified in the analysis.

Uploaded by

ahmadchughtai21
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Table of Contents

Question 1c: Rice Grain Analysis ........................................................................................................... 1

Question 1c: Rice Grain Analysis


clc; clear; close all;

% 1. Load and Preprocess


I = imread('[Link]');
background = imopen(I, strel('disk', 15));
I2 = I - background; % Remove uneven background
I3 = imadjust(I2); % Increase contrast

% 2. Binarize
bw = imbinarize(I3);
bw = bwareaopen(bw, 50); % Remove noise

% 3. Find Objects
cc = bwconncomp(bw, 4);
labeled = labelmatrix(cc);
RGB_label = label2rgb(labeled, 'spring', 'c', 'shuffle');
figure; imshow(RGB_label); title('Detected Rice Grains');

% 4. Calculate Statistics
graindata = regionprops(cc, 'basic');
grain_areas = [[Link]];
histogram(grain_areas); title('Histogram of Rice Grain Area');
disp(['Total Rice Grains Found: ' num2str([Link])]);

Total Rice Grains Found: 95

1
Published with MATLAB® R2025b

You might also like