Hi, For a forthcomming project, I require a piece of software that can measure the area of an irregular shape from a picture. This needs to work in a LAMP environment. I would be most grateful for any help. Thanks Mark
This question has been bothering me so I have been playing around. I picked the second attached image and produced the following code. <?php $im = new imagick( 'http://forums.digitalpoint.com/attachment.php?attachmentid=41098&d=1277195237' ); $im->setImageFormat( "png" ); $x = 1; $y = 1; // this will be white (background) $target = $im->getImagePixelColor($x, $y); // fill the background color red $im->floodfillPaintImage ('#ff0000',20000,$target,$x,$y,false); // get width and height of image $width = $im->getImageWidth(); $height = $im->getImageHeight(); // counter to count white pixels $counter = 0; // loop horizontally through the image for ($w =10; $w < $width; $w++) { // loop vertically through the image for ($h =10; $h < $height; $h++) { // get color at for the current position and compare it with white if ($target == $im->getImagePixelColor($w,$h)) { // if the pixel is white increment the counter $counter++; } } } echo ($width*$height)-$counter; ?> PHP: Now I have no idea how exact it is and even if it is correct is (really didn't want to count the pixels by hand). And this one will certainly not work for the first attached image either as there is a circle in the middle. But I guess it is a start to work with.
Just tried it with the other image and either by coincidence we have exactly the same number of white pixels (that would be really big coincidence) or script doesn't work properly (yes that is the option that makes the most sense). the thought was there so now you just need to fix it good luck
i think..., this will useful to you... list($width, $height, $type, $attr) = getimagesize("image url"); PHP: you will get each and every thing.. about that image..and finally echo the width, hight, type normally.. first give a try for it, and let me.. Thank you.
I don't think that he wants to do that. He wants to get the area of a shape that is in the image not just getting height and width. There was never the talk about that.
Oops, area that is present in the image..., how yar..! i am very exciting to see the comments then..,
This is so far the only with any code suggestion http://forums.digitalpoint.com/showthread.php?t=1845084&p=14437054#post14437054
The basic idea would be this: -you read all the pixels in the image in a matrix (a 2 dimensional array) -than you go through each line of the matrix and check every pixel: if the current pixel is black it means you found a border of the image and start counting the white pixels until you find black again (for odd number of border encounters you start counting, for even number of border encounters you stop counting; this resolves the holes also) But the problem is really a lot more complicated than this. Your image is a jpg. Jpg images have a lot of artifacts from compression, not all pixels are black or white, a lot are gray. You'll first need to created a method to approximate pixel's colors to either black or white. Also this method only works on closed shapes with no gap. Gaps have to be treated explicitly.
I am not sure what a Lamp environment is but we have some software that can do this measurement for you. We have af free, and payable versions, depending on your needs. The software is called KLONK Image Measurement, you can visit www.imagemeasurement.com to download you own version, i hope you can use this information.