Domanda

need a working example of how to do this, i have a bmp file showing the shape of a lake, the bmp's size is the rectangular area and known. i need to take this picture and estimate the lake size. so far, i have a script that generates a giant matrix of each pixel, telling me whether or not it's in the lake - but this isn't monte carlo! i need to generate random points and compare them against the shape somehow, this is where i'm getting stuck. i don't understand how to compare here, i don't have an equation for the shape or lines, i only have exact point information - either it is or isn't in the lake. so i guess i have the exact area already, but i need to find a way to compare random points against this.

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
È stato utile?

Soluzione

Here was the solution:

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;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top