需要一个如何做到这一点的工作示例,我有一个bmp文件显示湖的形状,bmp的大小是矩形区域并且已知。我需要拍这张照片并估算湖泊的大小。到目前为止,我有一个脚本生成每个像素的巨大矩阵,告诉我它是否在湖中 - 但这不是蒙特卡洛!我需要生成随机点并以某种方式将它们与形状进行比较,这就是我遇到的问题。我不明白如何比较这里,我没有形状或线的方程,我只有确切的点信息 - 它是否在湖中。所以我想我已经有了确切的区域,但我需要找到一种比较随机点的方法。
function Yes = Point_In_Lake(x,y,image_pixel)
[pHeight,pWidth]=size(image_pixel);
%pHeight = Height in pixel
%pWidth = Width in pixel
width = 1000; %width is the actual width of the lake
height = 500; %height is the actual height of the lake
%converting x_value to pixel_value in image_pixel
point_x_pixel = x*pWidth/width;
xl = floor(point_x_pixel)+1;
xu = min(ceil(point_x_pixel)+1,pWidth);
%converting y_value to pixel_value in image_pixel
point_y_pixel = y*pHeight/height;
yl = floor(point_y_pixel)+1;
yu = min(ceil(point_y_pixel)+1,pHeight);
%Finally, perform the check whether the point is in the lake
if (image_pixel(yl,xl)~=0)&&(image_pixel(yl,xu)~=0)&&(image_pixel(yu,xl)~=0)&&(image_pixel(yu,xu)~=0)
Yes=0;
else
Yes=1;
end
答案 0 :(得分:0)
以下是解决方案:
binaryMap = image_pixel
for i = 1:numel(image_pixel)
xrand = randperm(size(image_pixel,1),1);
yrand = randperm(size(image_pixel,2),1);
Yes(i) = Point_In_Lake(xrand,yrand,binaryMap);
end
PercentLake = length(find(Yes==1))/length(Yes);
LakeArea = (PercentLake * 500000)/43560;