# Hi, I have curve fitted an histogram using the gaussian function. Now I would like to know how to extract a series of cell diameters from the gaussian fit.

4 visualizzazioni (ultimi 30 giorni)
Akshay Kumar Pakala il 28 Ott 2021
Commentato: yanqi liu il 3 Nov 2021
Histogram with curve fit (x = cell diamters y = frequency)
##### 3 CommentiMostra 1 commento meno recenteNascondi 1 commento meno recente
Akshay Kumar Pakala il 28 Ott 2021
In my histogram the x values are cell diamters
Akshay Kumar Pakala il 29 Ott 2021
Also, I would like to know, how to create random 3d points based on my gaussian fit?

Accedi per commentare.

### Risposta accettata

yanqi liu il 1 Nov 2021
Modificato: yanqi liu il 2 Nov 2021
clc; clear all; close all;
[nr,nc,layers] = size(BW);
%% converting the image to 2d so the image can be labledd %%
if layers>1
BW = BW(:,:,1);
end
% end of lablling %%%%%%%%%%%%%%%%%
binaryimage = BW < 128;
bw = logical(binaryimage);
imwrite(bw, 'imagetoapp.jpg');
%% lablelling the image %%%%%%
[labeledimage, numberofblobs] = bwlabel(binaryimage,8);
props = regionprops(labeledimage, 'Equivdiameter');
x = numel(props);
y = zeros(x,1);
for i = 1:1:length(props)
y(i,1) = struct2array(props(i,1));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LAbled image to rgb
colouredimage = label2rgb(labeledimage,'jet', [0,0,0.5]);
coloredLabelsImage = label2rgb (labeledimage, 'jet', 'k', 'shuffle');
imshowpair(labeledimage,colouredimage,'montage')
hold on
%% generating histogram and curve fitting it using gaussian function%%%%%%%%%
figure()
y1 = histogram(y,45);
values = y1.Values;
a=y1.BinEdges;
for i = 1 : length(a)-1
b(i) = mean(a(i:i+1));
end
[barheights, position] = hist(y,45);
positiontranspose = position';
valuestranspose = values';
gauss = 'd + a*exp(-(1/2)*((x-b)/c)^2)'
gauss = 'd + a*exp(-(1/2)*((x-b)/c)^2)'
startpoints = [40 20 10 0.5];
myfit = fit(positiontranspose,valuestranspose,gauss,'start',startpoints);
hold on
plot(myfit)
z(:,1) = myfit(x);
zt=myfit(b);
%% plot properties
xlabel('cell diamters')
ylabel('frequency')
hold on; plot(b, zt, 'r*')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
##### 5 CommentiMostra 3 commenti meno recentiNascondi 3 commenti meno recenti
Akshay Kumar Pakala il 2 Nov 2021
Hey Yanqui Liu
I did not understand what you meant by that. Can you please explain?
Thank you
yanqi liu il 3 Nov 2021
such as two，make x----y
three，can as [x(1) x(2)]----y

Accedi per commentare.

### Più risposte (2)

yanqi liu il 29 Ott 2021
sir, may be upload the data mat file or the figure file to analysis
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Akshay Kumar Pakala il 29 Ott 2021
Also, I would like to know, how to create random 3d points based on my gaussian fit?

Accedi per commentare.

Akshay Kumar Pakala il 29 Ott 2021
Modificato: Walter Roberson il 1 Nov 2021
clc
clear all
[nr,nc,layers] = size(BW);
%% converting the image to 2d so the image can be labledd %%
if layers>1
BW = BW(:,:,1);
end
% end of lablling %%%%%%%%%%%%%%%%%
binaryimage = BW < 128;
bw = logical(binaryimage);
imwrite(bw, 'imagetoapp.jpg');
%% lablelling the image %%%%%%
[labeledimage, numberofblobs] = bwlabel(binaryimage,8);
props = regionprops(labeledimage, 'Equivdiameter');
x = numel(props);
y = zeros(x,1);
for i = 1:1:length(props)
y(i,1) = struct2array(props(i,1));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LAbled image to rgb
colouredimage = label2rgb(labeledimage,'jet', [0,0,0.5]);
coloredLabelsImage = label2rgb (labeledimage, 'jet', 'k', 'shuffle');
imshowpair(labeledimage,colouredimage,'montage')
hold on
%% generating histogram and curve fitting it using gaussian function%%%%%%%%%
figure()
y1 = histogram(y,45);
values = y1.Values;
[barheights, position] = hist(y,45);
positiontranspose = position';
valuestranspose = values';
gauss = 'd + a*exp(-(1/2)*((x-b)/c)^2)'
startpoints = [40 20 10 0.5];
myfit = fit(positiontranspose,valuestranspose,gauss,'start',startpoints);
hold on
plot(myfit)
z(:,1) = myfit(x);
%% plot properties
xlabel('cell diamters')
ylabel('frequency')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Histograms in Help Center e File Exchange

R2019a

### Community Treasure Hunt

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

Start Hunting!

Translated by