简体   繁体   English

使用Java确定图像中对象的长度和宽度

[英]Determining the Length and Width of Objects in an Image with Java

I want to be able to determine the length and width of all shapes in an image with a transparent background. 我希望能够确定具有透明背景的图像中所有形状的长度和宽度。 Can anyone give me some tips in java on how to do this? 谁能给我一些有关如何执行此操作的Java技巧?

Here is an example 这是一个例子

在此处输入图片说明

Edit: All pixels within each shape do not have the exact same RGB value, however, they are shades of the same color. 编辑:每种形状内的所有像素都不具有完全相同的RGB值,但是,它们是相同颜色的阴影。

Depends on what you are starting with and how you define length and width. 取决于您开始使用的内容以及定义长度和宽度的方式。 Image analysis is a large field, and there are several nice image analysis packages/libraries written in Java (have a look at http://imagej.nih.gov/ij/ and http://fiji.sc/ImgLib2 ). 图像分析是一个很大的领域,并且有几个用Java编写的不错的图像分析包/库(请访问http://imagej.nih.gov/ij/http://fiji.sc/ImgLib2 )。

However, if you have access to the RGB values of your image, all pixels in each structure have the exact same RGB value, and you are interested in finding the width and length of the bounding box of the structures in your image, then you can iterate through the x and y coordinates of the image an keep track of the minimum and maximum x and y coordinate for each RGB value. 但是,如果可以访问图像的RGB值,则每个结构中的所有像素都具有完全相同的RGB值,并且您有兴趣查找图像中结构的边界框的宽度和长度,那么您可以遍历图像的x和y坐标,以跟踪每个RGB值的最小和最大x和y坐标。 The difference between minimum and maximum in x will give the width, and in y will give you the height. x的最小值和最大值之间的差将给出宽度,y的最大值和最小值之间的差将给出宽度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM