Opened 5 years ago

Last modified 5 years ago

#3892 new defect

i.superpixels.slic: if kmeans converges, result should be one superpixel, not NULL

Reported by: mlennert Owned by: grass-dev@…
Priority: normal Milestone: 7.8.3
Component: Addons Version: unspecified
Keywords: i.superpixels.slic convergence color Cc:
CPU: Unspecified Platform: Unspecified

Description

In an automated script in which I run i.superpixels.slic, I sometimes have the situation that the zone I run the latter on is very small and very homogeneous leading to a convergence within the very first iteration of the kmeans in i.superpixels.slic (given the automatically determined parameter settings). I am ok with the entire area being considered as one single superpixel and would thus expect i.superpixels to label all pixels with 1. However, it labels all pixels with NULL. Is there any reason not to label a single superpixel ?

Somewhat as a side note, i.superpixels.slic crashes in that situation because of the color definition call in main.c (lines 707+708):

            Rast_make_random_colors(&colors, 1, numlabels);
            Rast_write_colors(outname, G_mapset(), &colors);

This can be easily solved by wrapping these calls into a check:

    if (numlabels > 1) {
            Rast_make_random_colors(&colors, 1, numlabels);
            Rast_write_colors(outname, G_mapset(), &colors);
    }
}}}.

Change History (2)

in reply to:  description comment:1 by mmetz, 5 years ago

Replying to mlennert:

In an automated script in which I run i.superpixels.slic, I sometimes have the situation that the zone I run the latter on is very small and very homogeneous leading to a convergence within the very first iteration of the kmeans in i.superpixels.slic (given the automatically determined parameter settings). I am ok with the entire area being considered as one single superpixel and would thus expect i.superpixels to label all pixels with 1. However, it labels all pixels with NULL. Is there any reason not to label a single superpixel ?

Homogeneous input has been fixed in a01f12c5, including your fix for color definitions.

Note that in case of homogeneous input, i.superpixels.slic will produce as many superpixels as there are seeds, not only one superpixel, because the distance to a superpixel center is considered together with spectral similarity.

Somewhat as a side note, i.superpixels.slic crashes in that situation because of the color definition call in main.c (lines 707+708):

            Rast_make_random_colors(&colors, 1, numlabels);
            Rast_write_colors(outname, G_mapset(), &colors);

This can be easily solved by wrapping these calls into a check:

    if (numlabels > 1) {
            Rast_make_random_colors(&colors, 1, numlabels);
            Rast_write_colors(outname, G_mapset(), &colors);
    }
}}}.

comment:2 by neteler, 5 years ago

Milestone: 7.8.3
Note: See TracTickets for help on using tickets.