Question

I'm trying to implement the floyd algorithm but it seems it doesn't works.

I used the pseudocode algorithm from wikipedia without floyd http://img15.hostingpics.net/pics/298623Capturedcran20140226165024.png

with floyd http://img15.hostingpics.net/pics/968250Capturedcran20140226165035.png

This is my code :

template<>
Image<ubyte>* Image<ubyte>::floydSteinberg() const
{
    Image<ubyte>* tmp = new Image<ubyte>(this->width, this->height);

    for (int i=0; i < width*height; i++)
            tmp->array[i]= this->array[i];


    for (int y = 0; y< this->height; y++){

        for (int x = 1; x<this->width; x++){

            ubyte oldpixel = tmp->pixel(x, y);
            ubyte newpixel  = (oldpixel > 128) ? 255 : 0;
            tmp->pixel(x,y) = newpixel;
            ubyte propagationErreur  = oldpixel - newpixel;

            tmp->pixel(x+1,y) =tmp->pixel(x+1,y) + 7.0/16 * propagationErreur;
            tmp->pixel(x-1,y+1) = tmp->pixel(x-1,y+1)  + 3.0/16 * propagationErreur ;
            tmp->pixel(x,y+1) = tmp->pixel(x,y+1)  + 5.0/16 * propagationErreur ;
            tmp->pixel(x+1,y+1) = tmp->pixel(x+1,y+1)  + 1.0/16 * propagationErreur ;

        }
    }


    return tmp;
}
Était-ce utile?

La solution

ubyte newpixel  = (oldpixel > 128) ? 0 : 255;

must be

ubyte newpixel  = (oldpixel > 128) ? 255 : 0;

Another possible issue: I suggest that propagationErreur should be signed type

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top