for (int x = 0; x < image.width(); ++x) {
for (int y = 0; y < image.height(); ++y) {
color = image.pixel(x,y);
if(color.red() == 0)
imageLabeled.setPixel(x,y, qRgb(0,0,0));
else{
color1 = imageLabeled.pixel(x, y-1);
color2 = imageLabeled.pixel(x-1, y);
if(color1.red() == 0 && color2.red() == 0)
{
imageLabeled.setPixel(x,y, qRgb(label, label, label));
label+=1;
}else if(color1.red() == 0 && color2.red() != 0)
imageLabeled.setPixel(x,y,color2.rgb());
else if(color1.red() != 0 && color2.red() == 0)
imageLabeled.setPixel(x,y, color1.rgb());
else if(color1.red() != 0 && color2.red() != 0)
{
if(color1.red() < color2.red())
imageLabeled.setPixel(x,y, color1.rgb());
else
imageLabeled.setPixel(x,y, color2.rgb());
}
}
}
}
for (int x = 0; x < image.width(); ++x) {
for (int y = 0; y < image.height(); ++y) {
color = image.pixel(x,y);
if(color.red() == 0)
imageLabeled.setPixel(x,y, qRgb(0,0,0));
else{
color1 = imageLabeled.pixel(x, y-1);
color2 = imageLabeled.pixel(x-1, y);
if(color1.red() == 0 && color2.red() == 0)
{
imageLabeled.setPixel(x,y, qRgb(label, label, label));
label+=1;
}else if(color1.red() == 0 && color2.red() != 0)
imageLabeled.setPixel(x,y,color2.rgb());
else if(color1.red() != 0 && color2.red() == 0)
imageLabeled.setPixel(x,y, color1.rgb());
else if(color1.red() != 0 && color2.red() != 0)
{
if(color1.red() < color2.red())
imageLabeled.setPixel(x,y, color1.rgb());
else
imageLabeled.setPixel(x,y, color2.rgb());
}
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks