Exemplo n.º 1
0
// same as above, but highlights a range of depths in red,
// and, colors all depths outside that range black in refImage
// highlight_low and high are values in [1,100]
BMP * CImage::toHighlightedBmp(int highlight_low, int highlight_high, BMP * refBmp)
{
    // scale range to be highlighted to [0,255]
    highlight_low = ((float) highlight_low) * 255.0/100.0 - 2.55;
    highlight_high = ((float) highlight_high) * 255.0/100.0;

    BMP * bmp = new BMP();
    bmp->SetSize(m_width, m_height);

    // for smaller output file size
    bmp->SetBitDepth(8);
    // 8-bit bitmaps need a color table
    CreateGrayscaleColorTable(*bmp);

    // add red to the color table
    RGBApixel highlightColor;
    highlightColor.Red = 255;
    highlightColor.Green = 0;
    highlightColor.Blue = 0;
    highlightColor.Alpha = 0;
    bmp->SetColor(highlight_low, highlightColor);

    // copy pixels to bmp
    for (int col = 0; col < m_width; col++)
    {
        for (int row = 0; row < m_height; row++)
        {
            float pixel = getValue(row, col, 0);
            if (highlight_low <= pixel && pixel <= highlight_high)
            {
                (* bmp)(col, row)->Red = 255;
                (* bmp)(col, row)->Green = 0;
                (* bmp)(col, row)->Blue = 0;
            }
            else
            {
                // Output is grayscale, so R, G, and B components are equal.
                // ScaleAndDisplayDisparityValues() et. al. in stereo.cpp have already
                //  scaled all float pixel values to [0, 255].
                ebmpBYTE byteVal = (ebmpBYTE) pixel;
                (* bmp)(col, row)->Red = byteVal;
                (* bmp)(col, row)->Green = byteVal;
                (* bmp)(col, row)->Blue = byteVal;

                // color non-highlighted areas black in refBmp
                (* refBmp)(col, row)->Red = 0;
                (* refBmp)(col, row)->Green = 0;
                (* refBmp)(col, row)->Blue = 0;
            }
        }
    }

    
    return bmp;
}
Exemplo n.º 2
0
        bool ExportBMP( const _TImg_t     & in_indexed,
                        const std::string & filepath )
    {
        //shorten this static constant
        typedef utils::do_exponent_of_2_<_TImg_t::pixel_t::mypixeltrait_t::BITS_PER_PIXEL> NbColorsPP_t;
        BMP output;
        output.SetBitDepth(_TImg_t::pixel_t::GetBitsPerPixel());

        if( in_indexed.getNbColors() != NbColorsPP_t::value )
        {
#ifdef _DEBUG
            assert(false);
#endif
            throw std::runtime_error( "ERROR: The tiled image to write to a bitmap image file has an invalid amount of color in its palette!" );
        }
        //copy palette
        for( int i = 0; i < NbColorsPP_t::value; ++i )
            output.SetColor( i, colorRGB24ToRGBApixel( in_indexed.getPalette()[i] ) );

        //Copy image
        output.SetSize( in_indexed.getNbPixelWidth(), in_indexed.getNbPixelHeight() );

        for( int i = 0; i < output.TellWidth(); ++i )
        {
            for( int j = 0; j < output.TellHeight(); ++j )
            {
                auto &  refpixel = in_indexed.getPixel( i, j );
                uint8_t temp     = static_cast<uint8_t>( refpixel.getWholePixelData() );
                output.SetPixel( i,j, colorRGB24ToRGBApixel( in_indexed.getPalette()[temp] ) ); //We need to input the color directly thnaks to EasyBMP
            }
        }

        bool bsuccess = false;
        try
        {
            bsuccess = output.WriteToFile( filepath.c_str() );
        }
        catch( std::exception e )
        {
            cerr << "<!>- Error outputing image : " << filepath <<"\n"
                 << "     Exception details : \n"     
                 << "        " <<e.what()  <<"\n";

            assert(false);
            bsuccess = false;
        }
        return bsuccess;
    }