count pixels within a specified range
5 次查看(过去 30 天)
显示 更早的评论
30 days ago, I asked a question in the forum which was resolved, the question consisted of a method to count the area produced by some circles.
I have an area of a map delimited by coordinates that form lines that in turn form a rectangle.
Within this rectangle, a random cloud of points is generated, which can be anywhere in it.
these points are the center of circles of radii r, for this example radius 300 meters.
dots can appear in the center or at the ends.
With the current code you can count the pixels that are equivalent to meters, of this area of the circles.
It is possible that the most extreme circles are out of the area that I need and the internal ones are very inside.
then I would need a program that counts them but that gives them a border, below I put examples.
In the example of the universe with stars, it can be seen that some stars have a spot that exceeds the study area, the idea is medical the area of the yellow spot and the area of the blue spot, all that this pr was the rectangle should not be measured.
It is important to bear in mind that the centers are generated randomly, therefore every interesting thing would be to generate an image with these points, within the reference frame and that at the same time generate the spots of radius R.
the question can be read in the following link
in the end it was determined that the code to do this was
T=readtable('dssddsdsdsdsdssd.xlsx') %See attached file
%table= lat lon
%3.3431406 -76.5235654
%3.3416997 -76.5217849
%3.3534876 -76.523249
%3.3531877 -76.52344
%3.3412194 -76.5213238
%3.3452824 -76.5181706
%3.3452824 -76.5181706
%3.3454431 -76.5165964
%3.3454431 -76.5165964
v5=300
J = table(T.lon,T.lat);
lla = [fliplr(table2array(J)) zeros(size(J,1),1)]
position = lla2flat(lla,[min(lla(:,1)) min(lla(:,2))],90,0) %geography to metters
r = v5 ;
C = position(:,1:2); % locations (x,y)
p = 10; % padding
s = ceil([(max(C(:,2))-min(C(:,2))),(max(C(:,1))-min(C(:,1)))] + r*2 + p*2);
C = round(C - [min(C(:,1)) min(C(:,2))] + r + p);
m = false(s);
m(sub2ind(s,C(:,2),C(:,1))) = 1;
m22 = bwdist(m)<=r;
totalarea = sum(m22(:)) % total number of white pixels = area
m23 = bwdist(m)>=r;
totalarea2 = sum(m23(:))
imshow('map(5).png')
imshow(m22)
m24=(totalarea*100)/(totalarea+totalarea2) %percentage occupied, but within the area that the program automatically generates, which is obviously wrong information
What happens is that I need you to count the pixels within a certain area, so I can know the real size of black and white pixels
another simpler graphic example
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/714502/image.jpeg)
lat lon
3.3622 -76.5243
3.3498 -76.5121
z
%points to evaluate
lat lon
3.3534876 -76.523249
3.3531877 -76.52344
3.3597285 -76.5240052
3.3591999 -76.5241002
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/714507/image.jpeg)
The idea is that I paint and piss within the parameters of the rectangle given by the initial coordinates, currently plotting and measuring within the maximum limit of the area of the outermost circuit, generating the error that it has more area than necessary, because in some cases the boundary of the rectangular wall can cut a circle and for other cases the circles are in the center of the image and external space is lost.
For example now I measure the% are of area adding and subtracting the black and white area, if however it is an error because the black area should be delimited by the coordinates of the walls of the rectangle
i need to put limits with the coordinates of the rectangle so that it would give me the real percentag
lat lon
3.3622 -76.5243
3.3498 -76.5121
%with this he formed the limits of the rectangle
%vertices are (lon1, lat1) (lon2, lat2) (lon2, lat1) (lon1, lat 2)
In example 1 of the stars, there is a reference frame (rectangular), the idea is to measure the area of all the internal stars and the part cut by the reference frame
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/714512/image.jpeg)
Another example with the same code :
Will it be possible to make the plotted image of black and white circles to measure the area, be drawn within specific margins? that is to say that it is drawn, for example, inside a straight line and where a circle touches the "wall" of the rectangle, is that area not counted?
I could have the coordinates of the rectangle and from there I would already have the "wall" where the circuit cannot advance.I made a small drawing and I will post it within the same link as the question already solved. with an exampleThank you.
1) the point cloud in longitude and latidut is
lat lon
3.4310571 -76.5249196
3.4330517 -76.5281573
3.4329578 -76.5278992
3.4259733 -76.5169571
3.4141012 -76.5322045
3.4132041 -76.5212801
3.4147463 -76.5212291
3.4200984 -76.5090573
3.4193326 -76.5304345
3.4191612 -76.5226856
3.4195618 -76.5180319
3.4194799 -76.5200061
3.4197733 -76.514478
3.4199018 -76.5121552
3.4191972 -76.5076382
3.4186178 -76.5074345
3.4172711 -76.5061631
3.4174853 -76.5059834
3.4131446 -76.5021961
3.413158 -76.5019253
3.410971 -76.5001202
3.4120227 -76.4916586
3.4146176 -76.4889863
3.4187462 -76.5249977
3.4121893 -76.5258832
3.4266255 -76.5285806
3.4291025 -76.5167687
3.4347968 -76.5141764
3.4321028 -76.5101736
3.4271533 -76.5053988
3.4185984 -76.4869869
3.4218167 -76.4909459
3.4248689 -76.4945159
3.4282086 -76.5327531
3.4354939 -76.5187478
3.4334187 -76.5101116
3.4352097 -76.5118256
3.4277076 -76.5368692
3.4309797 -76.5358927
3.4333837 -76.5351849
3.4349393 -76.5347021
3.4327974 -76.5364751
3.4182723 -76.5367191
3.4090406 -76.5355765
3.4077261 -76.5315237
3.4109503 -76.4893841
3.4086604 -76.5217632
3.4107276 -76.5215164
3.4166607 -76.5211731
3.4197919 -76.520905
3.4226876 -76.5205857
3.4247333 -76.5203818
3.4252902 -76.5180966
3.4295177 -76.5165489
3.4295177 -76.5165489
3.431641 -76.5163424
3.434254 -76.5147331
3.4347146 -76.5147384
3.4324815 -76.5163367
3.4213276 -76.517367
3.4175283 -76.5222486
3.412915 -76.5227287
3.410417 -76.523005
3.4071183 -76.5233778
3.4253297 -76.5015155
3.4339325 -76.4964618
3.4309045 -76.4980119
3.4244061 -76.5032478
3.4351374 -76.5232265
3.4346636 -76.5230613
3.4352634 -76.5206634
3.4330464 -76.5264623
3.4329822 -76.525545
3.432503 -76.5272398
3.431776 -76.528092
3.4305833 -76.5299112
3.4284118 -76.5320919
3.42642 -76.5337575
3.4241897 -76.533956
3.4235712 -76.5346507
3.4203582 -76.5356673
3.4178333 -76.5365309
3.4186983 -76.5357638
3.4215123 -76.5348599
3.4260317 -76.5333472
3.431708 -76.53415
3.4312579 -76.5281195
3.4321469 -76.5268189
3.4104115 -76.5293914
3.4129524 -76.5282836
3.4116382 -76.5231909
3.4225161 -76.5052968
3.4223848 -76.5046797
3.4201063 -76.5077996
3.4198948 -76.5072551
3.4282383 -76.4985591
3.4307088 -76.4971941
3.4295397 -76.498683
3.4341627 -76.4954614
3.4186526 -76.5283958
3.420709 -76.5345703
3.4148539 -76.5343228
3.4143741 -76.5182786
3.4143097 -76.5204408
3.4127084 -76.5180348
3.4121921 -76.5152421
3.4101545 -76.5174233
3.4144032 -76.5129681
3.4171883 -76.5100628
3.4339407 -76.53169
3.4313357 -76.5324383
3.435523 -76.5321513
3.4296035 -76.527203
3.4293248 -76.5276801
3.4261009 -76.5289884
3.4230866 -76.5299733
3.4235895 -76.5295651
3.4198576 -76.5310217
3.4198307 -76.5307561
3.4168025 -76.5317512
3.416891 -76.5319739
3.4140367 -76.5326686
3.4140957 -76.5328912
3.4119804 -76.5336127
3.4118654 -76.5333713
3.4093833 -76.5341652
3.4096271 -76.534353
3.4072306 -76.5351255
3.4085317 -76.5191425
3.4089332 -76.5194188
3.4076618 -76.5207116
3.4112626 -76.5170021
3.4133751 -76.5148108
3.4176403 -76.510361
3.4163313 -76.5116723
3.4153969 -76.5043551
3.4084892 -76.4974891
3.4101436 -76.4990257
3.4144384 -76.503151
3.4351054 -76.5284981
3.4261281 -76.5275993
3.4261523 -76.527849
3.4229822 -76.5274654
3.4228698 -76.5277042
3.4193409 -76.5272482
3.4195142 -76.5274917
3.4174159 -76.5276934
3.4175039 -76.5274625
3.4152952 -76.5282755
3.4153355 -76.5280341
3.4136218 -76.5285115
3.4128266 -76.5289863
3.4105909 -76.5295951
3.4122988 -76.4918565
3.4172202 -76.4868609
3.414781 -76.4891394
3.4114073 -76.4938627
3.4161733 -76.4946323
3.413493 -76.4958315
3.4153673 -76.4960917
3.409121 -76.5029153
3.4107622 -76.5010752
3.4078625 -76.5035831
3.4223742 -76.5071477
3.4225534 -76.5073462
3.4296915 -76.5034007
3.4300717 -76.5034999
3.427595 -76.504774
3.4321119 -76.5024404
3.4273729 -76.5045942
3.4354533 -76.5004663
3.4320209 -76.5022017
3.4252149 -76.5060265
3.4250836 -76.5057395
3.4355899 -76.5261781
3.4306315 -76.5255236
3.4283743 -76.5244554
3.4276114 -76.5261325
3.4235978 -76.5259367
3.4216031 -76.5252152
3.4217371 -76.5227609
3.4199565 -76.5219831
3.4077286 -76.5265107
3.4108104 -76.525537
3.42046 -76.5240967
3.423772 -76.5242335
3.4260048 -76.5243488
3.4275149 -76.5116888
3.4254534 -76.5118604
3.42231 -76.5121072
3.4119459 -76.5144917
3.4120689 -76.5143116
3.410232 -76.5128663
3.4103927 -76.5127
3.4080554 -76.5104764
3.4079321 -76.5106856
3.410584 -76.5180612
3.4136912 -76.5177206
3.4146069 -76.519405
3.4281973 -76.5199898
3.4324517 -76.5213684
3.4319432 -76.5237341
3.4256217 -76.5249679
3.4257289 -76.5229053
3.4234424 -76.5215964
3.4102992 -76.5182481
3.4148131 -76.5178014
3.4211585 -76.517155
3.414896 -76.5176163
3.4173218 -76.5175815
3.4173192 -76.517375
3.4198733 -76.5172382
3.4197957 -76.5174501
3.4226928 -76.517037
3.4080927 -76.5165086
3.4072227 -76.5159668
3.4076885 -76.5163987
3.4144512 -76.4930341
3.4129628 -76.4915964
3.4176748 -76.4959094
3.419292 -76.4974544
3.4224996 -76.5005174
3.4207702 -76.4988491
3.4227033 -76.5040283
3.4205988 -76.5019228
3.4180153 -76.4994632
3.4162721 -76.4980081
3.4352152 -76.5141913
3.4335874 -76.5092426
3.4330037 -76.5074616
3.433582 -76.5052032
3.4336247 -76.5059327
3.4339756 -76.5031808
3.4327895 -76.501204
3.4337159 -76.5030869
3.4328028 -76.5008097
3.4318442 -76.4993533
3.4314239 -76.4980551
3.4344601 -76.5118336
3.4192084 -76.5207168
3.4193369 -76.5181929
3.4194627 -76.5159237
3.4196073 -76.5133407
3.4197599 -76.5103903
3.428547 -76.5330845
3.4121579 -76.4873705
3.4297281 -76.5109285
3.4261112 -76.5168337
3.4229298 -76.5171669
2) the result image is
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/714517/image.jpeg)
3) the idea is that the points are plotted in a "rectangular" range demarcated by coordinates
for example:
lat lon
3.4356 -76.5369 %lan and lot 1
3.4071 -76.4868 %lan and lot 2
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/714522/image.jpeg)
How do I get it to plot and measure me within the geometric limits of the rectangle, formed by the given coordinates?
Thank you
zzz
1 个评论
darova
2021-8-20
Here is the data scaled. The data converted from lat/lon to row/column. Just convert rectangle coordinates the same way and cut an area you interested in
s = ceil([(max(C(:,2))-min(C(:,2))),(max(C(:,1))-min(C(:,1)))] + r*2 + p*2);
C = round(C - [min(C(:,1)) min(C(:,2))] + r + p);
采纳的回答
DGM
2021-8-20
编辑:DGM
2021-8-20
If I'm understanding the problem right:
m = false(s);
m(sub2ind(s,C(:,2),C(:,1))) = 1;
m = bwdist(m)<=r;
%m(:,[1:corners(1,1) corners(2,1):end]) = 0;
%m([1:corners(1,2) corners(2,2):end],:) = 0;
m = m(corners(1,2)+1:corners(2,2)-1,corners(1,1)+1:corners(2,1)-1);
totalarea = sum(m(:)) % total number of white pixels = area
coverage = mean(m(:)) % relative area
imshow(m); hold on
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/717154/image.png)
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!