Menu ▾ ▴

#24 New 'monochrome' function fixes ConvertToStandardType and...

None
closed
None
5
2018-07-31
2009-08-18
No

In my attempt to make ConvertToStandardType work also with RGB(A)16 and RGB(A)F images
I implemented a general function, for transforming an rgb image to monohrome one.
It is 'general' because R,G,B contributions to the final image are variable (including negative values),
in the end the function work exactly as Channel Mixer in PS (with monochrome checked)

The important part is that the function works with all standard FI RGB pixel formats and the result is in the same pixel type (byte ushort float), because of this now ConvertToStandardType and ConvertToGrayscale also work on RGB(A)16 and RGB(A)F images. It can also be used to compute Luminance for tone mapping and histogram algorithms, but I have not implemented these so far.

Patching:

  • Place the attached files in Source directory of FreeImage
  • add in freeimage.h:
    DLL_API FIBITMAP * DLL_CALLCONV
    FreeImage_Monochrome(FIBITMAP *src, float rscale FI_DEFAULT(0.299), float gscale FI_DEFAULT(0.587), float bscale FI_DEFAULT(0.144), int opt FI_DEFAULT(-1));

Discussion

  • Mihail Naydenov

    Mihail Naydenov - 2009-08-18

    'monochrome' function and Convert* enhancements

     
  • Hervé Drolon

    Hervé Drolon - 2009-08-22

    Hi Mihail,
    I will look at your patch soon. As a first analysis, your formula for 8-bit <--> 16-bit conversion seems to be wrong.
    Can you give me the list of conversions you need ?
    Also, if a channel mixer is needed, I can also add one to FreeImage.
    Lastly, formula for greyscale conversion is old and should be changed in order to use Rec. 709 (already used for tone mapping). I will look at this.

    Hervé

     
  • Mihail Naydenov

    Mihail Naydenov - 2009-08-24

    Thanks for the interest.

    Its a bit hard for me to respond to your comment, so I will just answer line by line.

    "your formula for 8-bit <--> 16-bit conversion seems to be wrong"
    I dont do any 'bit conversions', just use the new function (which preserves bit depth) to make it possible the old conversion functions to work with more formats...

    "Can you give me the list of conversions you need ? "
    I just wanted to make the existing functions work with more formats. I indeed need some more conversions, but I dont think they are a good candidate for inclusion in FI anyway, so I have implemented them in my one code. (a simple example is RGB(A)16 converted trough divide-by-255. This is doable in FI right now, but has to be done channel by channel.)

    "..if a channel mixer is needed, I can also add one to FreeImage."
    I was hoping the new 'monochrome' function is a pretty good candidate for such a function! If I dont miss some big point, the only downside it has is that it does not work with palettes/packed-pixel images. But, as personal opinion, the codeblot is not worth it, one can aways convert-to-standard.

    "formula for greyscale conversion is old and should be changed"
    Nothing is easier than that:)

     
  • Hervé Drolon

    Hervé Drolon - 2009-08-25

    About the division by 255, note that FreeImage_ConvertTo24Bits works with RGB16 and FreeImage_ConvertTo32Bits works with RGBA16.

     
  • Mihail Naydenov

    Mihail Naydenov - 2009-08-26

    Oh, I have missed that! I now see its even in the docs!
    Sorry, my mistake.

     
  • Hervé Drolon

    Hervé Drolon - 2018-07-31
    • status: open --> closed
    • Group: -->
     
  • Hervé Drolon

    Hervé Drolon - 2018-07-31

    Patch no longer needed in release 3.18.0.
    Please open a new ticket if your problem persist.

     

Anonymous
Anonymous

Add attachments
Cancel