Segment two images by clustering.
class_2dim2 performs a classification with two single-channel images. First a two-dimensional histogram of the two images is computed (histo_2dim__). In this histogram the first maximum is extracted; it serves as the first cluster center. The histogram is computed with the intersection of the domains of both images (see reduce_domain). After this, all pixels in the images, which are at most Threshold pixels from the cluster center in the maximum norm, are determined. These pixels form one output region. Next, the pixels thus classified are deleted from the histogram so that they are not taken into account for the next class. In this modified histogram again the maximum is extracted; it again serves as a cluster center. The above steps are repeated NumClasses times; thus, NumClasses output regions result. Only pixels defined in both images are returned.
Both input images must have the same size.
Image1 (input_object) |
image -> object : byte |
First input image. |
Image2 (input_object) |
image -> object : byte |
First input image. |
Classes (output_object) |
region-array -> object |
Segmentation result. |
Threshold (input_control) |
integer -> integer |
Threshold (maximum distance to the cluster's center). | |
Default value: 15 | |
Suggested values: 0, 2, 5, 8, 12, 17, 20, 30, 50, 70 |
NumClasses (input_control) |
integer -> integer |
Number of classes (cluster centers). | |
Default value: 5 | |
Suggested values: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 15, 20, 30, 40, 50 |
#include "HCPP.H" #includeint main (int argc, char *argv[]) { if (argc != 2) { cout << "Usage : " << argv[0] << " 'image' " << endl; return (-1); } HImage colimg (argv[1]), green, blue; HWindow w; long nc; if ((nc = colimg.CountChannels ()) != 3) { cout << argv[1] << " is not a rbg-image " << endl; return (-2); } colimg.Display (w); HImage red = colimg.Decompose3 (&green, &blue); HRegionArray seg = red.Class2dim2 (green, 15, 5); w.SetDraw ("margin"); w.SetColored (12); seg.Display (w); w.Click (); return (0); }
class_2dim2 returns TRUE if all parameters are correct. The behaviour with respect to the input images and output regions can be determined by setting the values of the flags 'no_object_result', 'empty_region_result', and 'store_empty_region' with set_system. If necessary, an exception is raised.
decompose2, decompose3, median, anisotrope_diff__, reduce_domain
select_shape, select_grey__, connection
threshold__, histo_2dim__, class_2dim__, class_ndim1__, class_ndim2__