Rasterizing Tiff with JPEG compression with alpha channel

vshibaevvshibaev Global Mapper UserPosts: 8
edited April 2010 in SDK
Hello Mike!

My aim is to render layer from attached file (area.tif) with transparent background.
I trying to render layer using functions GM_DrawLayerList or GM_ExportRasterEx. I experimented with arguments of these functions, but the best result I can get contains "noise" pixels around real part of geofile (see attached AreaTifTile.bmp)
If I render layer with EraseBackground (or GM_ExportFlags_NoTransparent) then result looks good, but it is opaque.
Is there any way to get good result for this file?

Thanks in advance!
Vitaliy Shibaev
area.zip 503.2K

Comments

  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited April 2010
    Vitaliy,

    If you use the GM_ExportRasterEx function and pass in the flags as follows:

    GM_ExportFlags_AddAlpha | GM_ExportFlags_JPGinTIFF

    Then you should get a JPG-compressed TIFF file with an alpha channel that causes all of the no-data areas to be marked as transparent.

    However, for data like this JPG-in-TIFF is really not the best compression given the simple nature of the data. Just basic LZW compression would likely work much better and be lossless as well. Use the GM_ExportFlags_UseLZW flag instead of the GM_ExportFlags_JPGinTIFF flag to use LZW compression rather than JPG in your TIFF file.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • vshibaevvshibaev Global Mapper User Posts: 8
    edited April 2010
    Hello Mike!

    Thank you for fast response! Will try your recommendation.

    Best regards,
    Vitaliy Shibaev
  • vshibaevvshibaev Global Mapper User Posts: 8
    edited April 2010
    Hello Mike!

    Please see attached tif in raster.zip. This is a result of this call in your sample application GMDLL_Tester (on click to "Save All to GeoTIFF" button for loaded layer area.tif from previous attachment), so you can reproduce it yourself:

    GM_ExportRaster(theSaveDialog.GetPathName(), GM_Export_GeoTIFF, NULL, NULL, 2705, 2048, GM_ExportFlags_AddAlpha | GM_ExportFlags_UseLZW);

    (GM_ExportFlags_JPGinTIFF produces similar result)

    As you can see exported file contains a lot of white (really points have background color, so if I do SetBackgroundColor to black - these points will have black color) points, is it a bug or there are no way to avoid this?

    Thank you for your help!
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited April 2010
    I took another look at your source data and discovered that your original area.tif file has a lot of pixels that are marked as nearly transparent, but not quite, so they count as valid pixels and end up in any output. You can see those pixels in the attached screenshot from Global Mapper. Is the area.tif the file that you have to start with or do you have a cleaner source image that you can use?

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • vshibaevvshibaev Global Mapper User Posts: 8
    edited April 2010
    Hello Mike!

    Unfortunately I start with this image, is it possible to get satisfactory result with this?
    I saw that these pixels exist, but why they change color depending on background of Global Mapper?

    Best regards,
    Vitaliy Shibaev
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited April 2010
    Vitaliy,

    The pixels change color because they are marked as translucency via an alpha channel, so they blend with whatever your view background color is. You could get rid of them with a two-step process. You would first export to a GeoTIFF but without the alpha channel flag set and with your background color set to black. Then load that file back in and use the GM_SetRasterDisplayOptions to make black transparent and use the mTransparentColorDist value to make other colors near black transparent as well (try a value of 32 or even 64 in this case). Then export that layer with the alpha channel flag set and this will hopefully get you what you want.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • vshibaevvshibaev Global Mapper User Posts: 8
    edited April 2010
    Hello Mike!

    Ok, thank you for your responses!
Sign In or Register to comment.