Recently to take the exam, so now do not write, afraid this period of time is not available to write. (The efficiency of the algorithm is not considered temporarily, time to solve the color information and efficiency problems)
Following the previous algorithm: http://blog.csdn.net/abcd_d_/article/details/41218549, this paper divides the watershed algorithm into regional merging, combining the histogram similarity degree of the region feature of HSV color space. And look at the effect: Figure one is the original picture, the second is the use of the previous article algorithm effect, figure three for the region after the effect of the merger. (Size has been adjusted by me)
(Figure I)
(Figure II)
(Figure III)
On the basis of the first article, the regional merging algorithm is added, which is the two key methods of the horizontal line. It can be seen that region merging can effectively remove the problem of fragmentation.
The first method is relatively simple, traversing the image to find the domain relationship and storing it in an object nodes of HashMap. The key is in the second method Arearcombine (), which needs to traverse the region in the nodes and, based on the consolidation criteria (here, the area size and the area similarity), to determine whether to merge the area into the appropriate field, so that the two regions become a new region. (This involves the merging of adjacency graphs) over and over again until no region is merged.
The problem seems simple, but the problem is that nodes this data structure after each traversal will be modified, so related to HashMap and other sets of different in the traversal, but also to modify the problem. The method of this article is relatively stupid, is to use the first record to modify the information, and then after the completion of the loop to modify (this trouble, there is a better way of friends, please enlighten ^_^).
Finally, this article is to be merged according to the regional characteristics, so an auxiliary class img_area_feature is added, which records the characteristics of the area and makes some merging of regions or adding pixel operations. In addition, the key of the region merging algorithm is the choice of merging criteria, the criterion of modifying size (area), similarity (similarity), and the modification of similar judgement methods have direct effect on the effect, which is also the shortcoming of this merging algorithm.
/** *///Here the consolidation guidelines directly affect the merge effect!!!!!!!!!!!!!!!!!!!! */if (size<30) {////Less than 10 pixels, merge into one of the pro domains Simmap.put (similarity, Child.getkey ());} else if (similarity<0.1&&similarity!=-1&&size<500) {///greater than 10 pixels, The Simmap.put (Similarity, Child.getkey ()) is selectively merged according to the saturation difference and tonal difference with the pro domain;} else if (similarity<0.2&&similarity!=-1&&size<200) {///greater than 10 pixels, The Simmap.put (Similarity, Child.getkey ()) is selectively merged according to the saturation difference and tonal difference with the pro domain;}
For example, to change the above judging condition size<30 to size<100 then the effect is as follows (Figure IV), you can see that the effect changes very clearly:
:
(Figure IV)
Finally attach the code address: http://download.csdn.net/detail/abcd_d_/8223951 ( to a point: recently to download, integral tense, so ... )
Beginner, Java uses watershed algorithms for Image Segmentation (ii)