32-bit grayscale image

1,576 views
Skip to first unread message

FP

unread,
Nov 5, 2018, 10:55:42 AM11/5/18
to fltk.general
Hi all,

I was looking for a nice C++ GUI framework and came across FLTK.
I am dealing with grayscale images where each pixel has a floating precision.
Re-scaling such images from 0-255 is not doable since I have to combine them and it is important that each value keeps its original value and sign (there are also negative pixels).
I am reading the documentation of FLTK but I do not seem to find a way to display such images from file.
It looks like 32-bit are always interpreted as RGB, and grayscale images can be at most 8-bit depth.
Is there a way to correctly display and edit 32-bit single-channel images with FLTK?

Thanks a lot in advance.
Best,

FP

Albrecht Schlosser

unread,
Nov 5, 2018, 11:15:07 AM11/5/18
to fltkg...@googlegroups.com
On 05.11.2018 16:53 FP wrote:
> Hi all,
>
> I was looking for a nice C++ GUI framework and came across FLTK.
> I am dealing with grayscale images where each pixel has a floating
> precision.
> Re-scaling such images from 0-255 is not doable since I have to combine
> them and it is important that each value keeps its original value and
> sign (there are also negative pixels).
> I am reading the documentation of FLTK but I do not seem to find a way
> to display such images from file.

Correct, there is no function to read such images in FLTK. FLTK
integrates libpng and libjpeg to read images.

> It looks like 32-bit are always interpreted as RGB, and grayscale images
> can be at most 8-bit depth.

That's correct - although 32-bit would be RGBA, and RGB is only 24-bit,
but that's probably what you meant anyway.

> Is there a way to correctly display and edit 32-bit single-channel
> images with FLTK?

Basically you can display every image you like with FLTK, as long as
each color (and alpha) channel is only 8 bits - for display.
Fl_RGB_Image uses a pixel buffer you can fill with arbitrary bits.

As said above, there is no direct method to read 32-bit per channel
grayscale images. You would have to write this yourself (or use another
library if there's one that suits your needs). I uses libtiff in one of
my applications to read tiff images, for instance. You would also have
to write your image manipulation code to combine them, as you wrote
above, but I assume this code exists already.

After doing so you could convert the resulting image to 8-bit per
channel RGB(A) or grayscale for display only if this is sufficient, but
that's something I can't tell.

ISTR that there are image manipulation programs written in FLTK that
deal with more bits per channel but I can't remember which program(s).
Maybe someone else can tell.

FP

unread,
Nov 5, 2018, 11:57:21 AM11/5/18
to fltk.general
Hi Albrecht,

Thanks a lot for the answer (yes, I meant RGBA).
One option could be to convert the images to 8-bit only for display, as a visual guide (the user would need to see them in order to decide how to combine them).
But for their linear combination I could work with the original floating-point precision in the background, and finally convert the result too and display it.
I look forward to hear if this is a good option, or if anyone has a better solution.
Regarding other libraries, unfortunately Qt is out of discussion since some algorithms I have to implement are confidential and I cannot share the full code (I would have gone for a free license).
I want to implement some tools not for commercial use, but just to ease some investigations I have to do. Still the core algorithms to be implemented are strictly confidential.
With wxWidgets I found building problems (it has conflicts with another libraries I am using, DCMTK), FLTK could be nicely included and the code looks simple enough for me.

Thanks a lot again for the tips.

Best,
FP

Albrecht Schlosser

unread,
Nov 5, 2018, 2:27:25 PM11/5/18
to fltk.general
On 05.11.2018 17:57 FP wrote:

> One option could be to convert the images to 8-bit only for display, as
> a visual guide (the user would need to see them in order to decide how
> to combine them).
> But for their linear combination I could work with the original
> floating-point precision in the background, and finally convert the
> result too and display it.
> I look forward to hear if this is a good option, ...

That's probably what I would do. I think this is not a bad solution
because I don't think that users would see a difference, but working
with the original images for your algorithms is still possible.

> ...or if anyone has a better solution.

> Regarding other libraries, unfortunately Qt is out of discussion ...

I didn't mean to suggest using another library for the GUI (instead of
FLTK) but another library to load the images. As I wrote I used libtiff
to load tiff images in an FLTK application.

You may also want to read Ian's article about image manipulation in FLTK
("Mini-howto: Display Arbitrary Data as an Image")
http://www.fltk.org/articles.php?L468

and maybe also take a look at this FLTK image viewer (flimage):
http://www.fltk.org/articles.php?L1521

Note that I didn't use nor test flimage, please evaluate yourself.

Edzard Egberts

unread,
Nov 6, 2018, 2:20:35 AM11/6/18
to 'ed' via fltk.general
> One option could be to convert the images to 8-bit only for display, as
> a visual guide (the user would need to see them in order to decide how
> to combine them).

This is the way, you should go. These days I'm analysing cloud images by
RGB ratios, e.g. (B/G + R/G), or ((0.299 * R + 0.587 * G + 0.114 * B) -
Max(R, G, B) + Min(R, G, B)) and the results are stored to OpenCV float
arrays dimensioned by width and heigth of the images. Displayed as
grayscale image they normally look black and it is necessary to blow up
the range to make the original image visible again.

> But for their linear combination I could work with the original
> floating-point precision in the background, and finally convert the
> result too and display it.

This is exactly, what I'm doing. In the following example method the
original "cv_mat" is an array rows*cols*float and will be converted to
rows*cols*uchar. Min_Max() is a function, that looks for the largest and
smallest value.

cv_mat cv_mat::Ratio2Gray() const
{
cv_mat Gray(rows, cols, CV_8U, cv::Scalar::all(0.0));
if (channels()== 1 && depth()== CV_32F)
{
float Min, Max, Val;
Min_Max(Min, Max, true);
float Span= Max - Min;
if (Span)
for (int i = 0; i < rows; ++i)
for (int j = 0; j < cols; ++j)
{ // subtract offset and convert to range 0..255
Val= at< float >(i, j);
if (Val) Gray.at< uchar >(i, j)= 255.0 * (Val - Min)/Span;
}
}
return Gray;
}


Reply all
Reply to author
Forward
0 new messages