示例#1
0
bool IPLSynthesize::processInputData(IPLImage*, int, bool)
{
    if(isResultReady())
    {
        //return true;
    }

    // delete previous result
    delete _result;
    _result = NULL;

    // get properties
    _type       = getProcessPropertyInt("type");
    _width      = getProcessPropertyInt("width");
    _height     = getProcessPropertyInt("height");
    _amplitude  = getProcessPropertyDouble("amplitude");
    _offset     = getProcessPropertyDouble("offset");
    _wavelength = getProcessPropertyInt("wavelength");
    _direction  = getProcessPropertyInt("plane_direction");
    _decay      = getProcessPropertyInt("decay");

    IPLColor color = getProcessPropertyColor("flat_color");

    if( _type == 0 )
        _result = new IPLImage( IPL_IMAGE_COLOR, _width, _height );
    else
        _result = new IPLImage( IPL_IMAGE_GRAYSCALE, _width, _height );

    double dx = (double)_width / 2.0;
    double dy = (double)_height / 2.0;
    double direction = _direction / 180.0 * PI; // deg to rad

    IPLImagePlane* plane = _result->plane( 0 );

    int progress = 0;
    int maxProgress = _result->height();

    switch( _type )
    {
    case 0: // flat plane
        for( int y=0; y<_height; y++ )
        {
            notifyProgressEventHandler(100*progress++/maxProgress);
            for( int x=0; x<_width; x++ )
            {
                _result->plane(0)->p(x,y) = color.red();
                _result->plane(1)->p(x,y) = color.green();
                _result->plane(2)->p(x,y) = color.blue();
            }
        }
        break;
    case 1: // plane wave
        for( int y=0; y<_height; y++ )
        {
            notifyProgressEventHandler(100*progress++/maxProgress);
            for( int x=0; x<_width; x++ )
            {
                double dist = (x)*cos( direction ) + (_height-y)*sin( direction );
                double fade = (_decay!=0) ? exp( -dist/_decay ) : 1.0;
                double value = _amplitude * cos(dist/_wavelength * PI * 2.0) * fade + _offset;
                plane->p(x,y) = ( (value<0.0)? 0.0 : (value>1.0)? 1.0 : value );
            }
        }
        break;
    case 2:// center wave
        for( int y=0; y<_height; y++ )
        {
            notifyProgressEventHandler(100*progress++/maxProgress);
            for( int x=0; x<_width; x++ )
            {
                double dist = sqrt( (x-dx)*(x-dx) + (y-dy)*(y-dy) );
                double fade = (_decay!=0) ? exp( -dist/_decay ) : 1.0;
                double value = _amplitude * cos( dist/_wavelength * PI * 2.0 ) * fade + _offset;
                plane->p(x,y) = ( (value<0.0)? 0.0 : (value>1.0)? 1.0 : value );
            }
        }
        break;
    }

    return true;
}
示例#2
0
bool IPLCanvasSize::processInputData(IPLImage* image , int, bool)
{
    // delete previous result
    delete _result;
    _result = NULL;
    int width  = image->width();
    int height = image->height();

    _result = new IPLImage(image->type(), width, height);

    // get properties
    int         new_width   = getProcessPropertyInt("width");
    int         new_height  = getProcessPropertyInt("height");
    IPLColor    color       = getProcessPropertyColor("color");
    int         anchor      = getProcessPropertyInt("anchor");

    _result = new IPLImage(image->type(), new_width, new_height);

    int progress = 0;
    int maxProgress = image->height() * image->getNumberOfPlanes();
    int nrOfPlanes = _result->getNumberOfPlanes();

    //Anchor:Top Left|Top|Top Right|Left|Center|Right|Bottom Left|Bottom|Bottom Right

    // Top Left
    int offset_x = 0;
    int offset_y = 0;
    if(anchor == 1)
    {
        // Top
        offset_x = (new_width-width) * 0.5;
        offset_y = 0;
    }
    else if(anchor == 2)
    {
        // Top Right
        offset_x = new_width-width;
        offset_y = 0;
    }
    else if(anchor == 3)
    {
        // Left
        offset_x = 0;
        offset_y = (new_height-height) * 0.5;
    }
    else if(anchor == 4)
    {
        // Center
        offset_x = (new_width-width) * 0.5;
        offset_y = (new_height-height) * 0.5;
    }
    else if(anchor == 5)
    {
        // Right
        offset_x = new_width-width;
        offset_y = (new_height-height) * 0.5;
    }
    else if(anchor == 6)
    {
        // Bottom Left
        offset_x = 0;
        offset_y = new_height-height;
    }
    else if(anchor == 7)
    {
        // Bottom
        offset_x = (new_width-width) * 0.5;
        offset_y = new_height-height;
    }
    else if(anchor == 8)
    {
        // Bottom Right
        offset_x = new_width-width;
        offset_y = new_height-height;
    }

    if(nrOfPlanes == 1)
    {
        addWarning("For grayscale images, the red slider is used as background value.");
    }

    #pragma omp parallel for
    for( int planeNr=0; planeNr < nrOfPlanes; planeNr++ )
    {
        IPLImagePlane* plane = image->plane( planeNr );
        IPLImagePlane* newplane = _result->plane( planeNr );
        ipl_basetype background = 0.0;

        if(planeNr == 0)
            background = color.red();
        else if(planeNr == 1)
            background = color.green();
        if(planeNr == 2)
            background = color.blue();

        for(int y=0; y<new_height; y++)
        {
            // progress
           notifyProgressEventHandler(100*progress++/maxProgress);

            for(int x=0; x<new_width; x++)
            {
                int from_x = x - offset_x;
                int from_y = y - offset_y;

                // check if inside source image
                if(from_x < 0 || from_y < 0 || from_x > plane->width() || from_y > plane->height())
                {
                    newplane->p(x, y) = background;
                }
                else
                {
                    newplane->p(x, y) = plane->p(from_x, from_y);
                }
            }
        }
    }

    return true;
}
示例#3
0
uchar* IPLImage::rgb32()
{
    if(_type == IMAGE_BW)
    {
        int i=0;
        for(int y=0; y < _height; y++)
        {
            for(int x=0; x < _width; x++)
            {
                uchar val = plane(0)->p(x,y) * FACTOR_TO_UCHAR;
                val = val < 0x80 ? 0x00 : 0xFF;
                _rgb32[i++] = val;
                _rgb32[i++] = val;
                _rgb32[i++] = val;
                _rgb32[i++] = 0xFF;
            }
        }
    }
    else if(_type == IMAGE_GRAYSCALE)
    {
        int i=0;
        for(int y=0; y < _height; y++)
        {
            for(int x=0; x < _width; x++)
            {
                uchar val = (plane(0)->p(x,y) * FACTOR_TO_UCHAR);
                _rgb32[i++] = val;
                _rgb32[i++] = val;
                _rgb32[i++] = val;
                _rgb32[i++] = 0xFF;
            }
        }
    }
    else if(_type == IMAGE_COLOR)
    {
        int i=0;
        for(int y=0; y < _height; y++)
        {
            for(int x=0; x < _width; x++)
            {
                uchar r = plane(0)->p(x,y) * FACTOR_TO_UCHAR;
                uchar g = plane(1)->p(x,y) * FACTOR_TO_UCHAR;
                uchar b = plane(2)->p(x,y) * FACTOR_TO_UCHAR;
                _rgb32[i++] = b;
                _rgb32[i++] = g;
                _rgb32[i++] = r;
                _rgb32[i++] = 0xFF;
            }
        }
    }
    else if(_type == IMAGE_ORIENTED)
    {
        double maxMag = 0.0;
        for(int x=0; x<_width; x++)
            for(int y=0; y<_height; y++)
                if( plane(0)->p(x,y) > maxMag ) maxMag = plane(0)->p(x,y);

        int i=0;
        for(int y=0; y < _height; y++)
        {
            for(int x=0; x < _width; x++)
            {
                ipl_basetype phase = fmod(plane(1)->p(x,y), 1.0);
                ipl_basetype magnitude = plane(0)->p(x,y) / maxMag;

                if(phase < 0)
                    phase = 0;
                if(phase > 1)
                    phase = 1;

                IPLColor color = IPLColor::fromHSV(phase, 1.0,  magnitude);

                uchar r = color.red()   * FACTOR_TO_UCHAR;
                uchar g = color.green() * FACTOR_TO_UCHAR;
                uchar b = color.blue()  * FACTOR_TO_UCHAR;
                _rgb32[i++] = b;
                _rgb32[i++] = g;
                _rgb32[i++] = r;
                _rgb32[i++] = 0xFF;
            }
        }
    }

    return _rgb32.data();
}