Float image data support

135 views
Skip to first unread message

Jeremy Fergason

unread,
Oct 20, 2015, 5:01:21 AM10/20/15
to OpenJPEG
Hello,

Does OpenJPEG 2.1 support float as the data type of a component?  If so, can anyone point me towards an example of how to do this?

Thanks,

Jeremy Fergason

szuk...@arcor.de

unread,
Oct 20, 2015, 3:09:29 PM10/20/15
to open...@googlegroups.com
On Tue, 20 Oct 2015 01:04:55 -0700 (PDT), Jeremy wrote:

>Does OpenJPEG 2.1 support float as the data type of a component?

No.

>If so, can anyone point me towards an example of how to do this?

No.

The specification 15444-1 from 2004 says max. 38 bits. Search for
'1544-1.pdf' in the internet.

winfried

Jeremy Fergason

unread,
Oct 20, 2015, 6:58:02 PM10/20/15
to OpenJPEG
Thanks for the info.  I guess I don't understand that part about max 38 bits though.  I thought float was only 32 bits?

Also is there a way to use UINT32_T for the input data?  I have only been able to make UINT8 and UINT16 work successfully.

-Jeremy

szuk...@arcor.de

unread,
Oct 20, 2015, 8:02:27 PM10/20/15
to open...@googlegroups.com
On Tue, 20 Oct 2015 15:58:01 -0700 (PDT), Jeremy wrote:

>Also is there a way to use UINT32_T for the input data?
>I have only been able to make UINT8 and UINT16 work successfully.

From 'openjpeg.h':

typedef struct opj_image_comp {
(...)
/** image component data */
OPJ_INT32 *data;
/** alpha channel */
OPJ_UINT16 alpha;
} opj_image_comp_t;

The 38 bit are the maximum specified in 1544-1. The maximum
of OPENJPEG is 31 bit: OPJ_INT32.

What did you do to fail with UINT32_T data?

winfried

Jeremy Fergason

unread,
Oct 20, 2015, 9:43:28 PM10/20/15
to OpenJPEG
When I set BPP and PREC to 32 I get all zeros on the decode,  If I set it to something between 16 - 30 I get wrap around at 65k.  Here's the code I'm using to compress:

 const OPJ_COLOR_SPACE color_space = OPJ_CLRSPC_GRAY;

  parameters_.cod_format = JP2_CFMT;
  parameters_.numresolution = 6;

  // Currently only support lossless compression
  parameters_.tcp_rates[0] = 0;
  parameters_.tcp_numlayers++;
  parameters_.cp_disto_alloc = 1;

  // component parameters
  opj_image_cmptparm_t component_params_;
  component_params_.sgnd = 0;
  component_params_.dx = 1;
  component_params_.dy = 1;
  component_params_.prec = 32;
  component_params_.bpp = 32;
  component_params_.w = width;
  component_params_.h = height;

  opj_image_t* image = opj_image_create(1, &component_params_, color_space);
  assert(image);

  // Even though this was set on the component parameters, it must be
  // done again on the whole image.  Otherwise the opj_start_compress
  // function will fail with no error messages ... quite annoying really.
  image->x1 = width;
  image->y1 = height;

  // set the data, for grayscale there is only a single component
  for (int xx=0; xx<height*width; ++xx)
  {
    image->comps[0].data[xx] = img_data[xx];
  }

  // create codec with logging
  opj_codec_t* codec = NULL;
  opj_set_info_handler(codec, j2k::info_callback, NULL);
  opj_set_warning_handler(codec, j2k::warning_callback, NULL);
  opj_set_error_handler(codec, j2k::error_callback, NULL);
  codec = opj_create_compress(OPJ_CODEC_JP2);
  opj_set_info_handler(codec, j2k::info_callback, NULL);
  opj_set_warning_handler(codec, j2k::warning_callback, NULL);
  opj_set_error_handler(codec, j2k::error_callback, NULL);

  opj_setup_encoder(codec, &parameters_, image);

  std::string fname("/tmp/test.jp2");
  opj_stream_t* stream = opj_stream_create_default_file_stream(fname.c_str(), 
    OPJ_FALSE);
  assert(stream);

  bool success = opj_start_compress(codec, image, stream);
  if (!success)
  {
    std::cerr << "failed to start compression" << std::endl;
    opj_stream_destroy(stream);
    opj_destroy_codec(codec);
    opj_image_destroy(image);
    return success;
  }

  assert(success);
  success = opj_encode(codec, stream);
  assert(success);
  success = opj_end_compress(codec, stream);
  assert(success);

  opj_stream_destroy(stream);
  opj_destroy_codec(codec);
  opj_image_destroy(image);

Thanks!

Antonin - OpenJPEG

unread,
Oct 22, 2015, 3:57:19 AM10/22/15
to open...@googlegroups.com
Hi Jeremy,

OpenJPEG is actually known to be working with 16-bits integer samples (at some point in the process it requires higher precision which is why OPJ_UINT32 is also used). I actually don’t know what would be the behavior with 32-bits samples but I’m not very optimistic. Anyhow, feel free to submit an issue with 32-bits integer sample image, that would be interesting to debug.

As far as floating-point support is concerned, the answer is no indeed: this is part of 15444-2 (aka JPEG 2000 Part-2) and OpenJPEG is focusing on the core coding system (15444-1, aka JPEG 2000 Part-1).

Hth

Antonin

--
You are subscribed to the mailing-list of the OpenJPEG project (www.openjpeg.org)
To post: email to open...@googlegroups.com
To unsubscribe: email to openjpeg+u...@googlegroups.com
For more options: visit http://groups.google.com/group/openjpeg
OpenJPEG is mainly supported by :
* UCL Image and Signal Processing Group (http://sites.uclouvain.be/ispgroup)
* IntoPIX (www.intopix.com)

szuk...@arcor.de

unread,
Oct 22, 2015, 11:33:54 AM10/22/15
to open...@googlegroups.com
Jeremy,

could you send the original GRAYSCALE image and the width and height
of that image?

Or send a link to that image?

winfried

Callum Lerwick

unread,
Oct 29, 2015, 1:42:16 AM10/29/15
to openjpeg
On Tue, Oct 20, 2015 at 1:04 AM, Jeremy Fergason
<jeremy....@gmail.com> wrote:
> Hello,
>
> Does OpenJPEG 2.1 support float as the data type of a component? If so, can
> anyone point me towards an example of how to do this?

Not sure what you're doing, but if you're targeting humans, you might
consider mapping float onto integers via a log curve, this is what
Hollywood has been doing for ages now starting with the Cineon
standard:

https://en.wikipedia.org/wiki/Cineon
http://www.red.com/learn/red-101/redlogfilm-redgamma
Reply all
Reply to author
Forward
0 new messages