I would like to create a set of random points with a distance separating them from each other. I would also like to create various sets of random numbers
6 views (last 30 days)
Show older comments
For example i would like to create 50 random points that seprated by a distance of 20 from each other and another set of 27 random points that are seperated by a distance of 12 from each other. SImilarly, i would like to create a set of random for every bin of the histogram with the seperating distances respectively.
I am attaching the code that i used to generate the histogram
clc
clear all
BW = imread('binary.PNG');
[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)'
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('seperation distances')
ylabel('frequency')
hold on; plot(b, zt, 'r*')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
binary image
2 Comments
Chris
on 5 Nov 2021
The histogram shows the number of regions with a diameter (approximately, since these aren't circles) that fits in each bin. So, for example, the large region in the lower left is the only region with a diameter >100 px.
So that I understand your request: The bin [49.67, 51.94] has two regions. You want two pixels somewhere in a new figure that are ~50 pixels apart from each other? Or two points around the circumference of one of the 50px regions? Or something else?
Answers (0)
See Also
Categories
Find more on Histograms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!