How to measure area and diameter of flat uneven scanned image (not 3D) using java?

Asked

Viewed 2,824 times

6

I’m from the health area and never took a course in Programming Language, but for some reasons I will need to make a software to help in my research.

I need to measure the total area and also area/3 of an image, already converting directly from pixel to cm. It is possible?

And the length from one end of the image to the other in cm? Is it possible? How do I do it? How do I start this?

  • Do you need the area of the entire image that will be provided as input to the software or just a part of the image? For example, do you need to recognize some pattern in the image and know only the area of this pattern (such as the area of certain coloring on a blade)? It might be interesting to offer an example and the result you expect would make it simpler to suggest a solution.

  • Hello our response so fast that I was scared of rsrsrs...so the image is like when you put an ink in your hand and stamp on an A4 sheet is that impression. So according to what I already do manually I discard, To calculate the length I took the ruler and measured the shortest length q found by the longest horizontal from one end of the palm to the other. making this division I found a value x q I need.

  • I haven’t finished...now the second index is to divide the palm into 3 areas A,B,C. And divide the area c by the sum of the 3 areas...and did not want to do this manually.. a lot of work are for example 800 hands... That’s why the idea of creating this program

  • The idea was for me to scan the A4 sheet with the hand image. And use the image , did not want to change the size of it after scanning p not lose the real image..

  • 1

    Got it. Well, as soon as possible I’ll draft an answer to guide you, not the final solution, but the path for you. with some example. I will use A4 as the basis for converting pixels to CM as well. Thanks for the clarification.

  • Yes I’ve read some things about this account in pixel and convert p cm, in some articles of dentistry images, etcB.runo which your email or cell phone you could keep in touch with?

  • Deborah, any particular reason to use Java? What you want to do is a very common type of task, however, the normal procedure is to put a scale on the image, because even scanning the A4 sheet, the size of the image will vary and the error will be great. You can put the scale on the scanner over a white part of the sheet. Also look over the program Imagej, It has several tools for image analysis, including measuring distances and areas. You can automate tarreps and read all images in a few seconds.

Show 2 more comments

1 answer

4

Many colleagues have already provided you with great information via comments. And the principle of what they said is absolutely correct: you need to have a scale established with the relationship between the pixels of the image and the centimeters of objects in the real world (for example, every 10 pixels in the image corresponds to 20cm on the actual A4 sheet). Having this, just make a rule of three simple and you calculate the length in centimeters of an object measured in pixels.

As you have also commented, there are two ways to establish this scale:

  1. Calibration of the equipment. You mount the camera and the base of the objects (or the scanner) in a fixed way, so that the same photos are always produced, that is, with the same distance from the object and the same resolution. Then you take a photo (or make a scanner) and manually measure the scale obtained by configuring your program with it. While capturing the following images, this value will remain correct as long as you do not change the equipment involved.

  2. Automatic calibration based on a pattern. Whenever you obtain an image, you include together with the object of interest another object acquaintance, with an easy-to-detect pattern via computer vision algorithms (a chess band, for example). This known object must have fixed and also known dimensions. When processing the image, you first locate such an object, and measure its dimensions in pixels. As his real dimensions are known, you also use the rule of three to find the relation (scale) of the image. Ai, just apply it to the object of real interest.

It should be noted that in automated processes, in industry, in agriculture, and perhaps also in laboratories (as it seems to be your case), one usually uses approach 1 because it is very simple to control the image capture environment (and so it is not necessary to do additional processing to locate the pattern to each processed image).

As already mentioned, having the scale just extract the object of interest, make the measurement in pixels and make the conversion calculation to centimeters. You may have difficulties also in how to spoil the object of interest, but for this there are some methods.

The limiarization (thresholding) is a very simple method, which works well mainly in controlled environments (for example, if you have black ink on a white sheet of paper). The idea of this method is very simple: you choose a pixel value to be the threshold (Threshold in English, give the name of the method), and then go to the image and change to 0 (black) all pixels with value less than the chosen threshold and to 1 (white) all pixels with value greater than the chosen threshold. The final image will be a binary image (only 0 and 1) clearly delimiting your object of interest (of course, depending on an appropriate choice of threshold and whether your object of interest is clearer/prop than the background). I suggest reading this other question from SOPT, which deals precisely with this subject (in another problem area, but which serves it in the same way).

Another possible use method is regional growth (Region Growing). It is a little more complex, but still easy to understand. You "draw" a pixel to be the "seed" (the beginning of a new region). And then, go analyzing the neighboring pixels to see if they are similar (the similarity criterion you choose: it can be proximity values, if you want the same color to be grouped, for example). This process continues with neighbors' neighbors until they run out of neighboring pixels or the similarity indicates that there are no more neighbors to group. This new region is an object (it may be of interest, or it may be the background, for example). If pixels remain in the image not yet processed, you draw a new seed, and start a new region. It goes like this until it processes the whole image. In this my answer here from SOPT there is a detailed illustration of this method in another problem domain, but it can also help you.

After you separate the object of interest from the background, simply measure its dimensions. If you can also control the capture environment, it makes it easier because you can always put the object in a pre-established position (horizontal, for example), and then the length in pixels will be the amount of pixels in the image matrix counted on the x axis, and the width will be the amount of pixels in the matrix counted on the y-axis. The area, of course, is the amount of pixels in the extracted region.

P.S.: This blog contains a very didactic tutorial (although in English) on some principles of image processing. Worth the reading.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.