Board index » delphi » JPG: resize, brightness, contrast ?

JPG: resize, brightness, contrast ?

How to load, resize and save JPG images in my app (D5) ?
I must often resize many and many JPG photos and sometimes change their
brightness and contrast...
Many thanx for any help, link, unit, component,...
Tom
 

Re:JPG: resize, brightness, contrast ?


Quote
"Tom Brendl" <tbre...@post.cz> wrote in message

news:832ur9$68a2@forums.borland.com...

Quote
> How to load, resize and save JPG images in my app (D5) ?
> I must often resize many and many JPG photos and sometimes change their
> brightness and contrast...

You'll likely need a commercial product to do this well.  You might try:
www.imagelib.com or www.leadtools.com .

To manipulate a JPG, you need to convert it to a TBitmap before you
can get at the pixel data via Scanline.  But conversions from JPG to
BMP and back could result in additional loss in image quality since
the JPG compression is lossy.

You can display a JPG any size in a TImage by using the Stretch
property of the TImage.

There is some info about how to change the brightness of a TBitmap
in Section C of
http://www.efg2.com/Lab/Library/Delphi/Graphics/Algorithms.htm

For links about resizing, look for "Resampling" in Section C of
this same page.

I've never found any good links about contrast enhancement.  It's
fairly easy for grayscale images, but much more difficult for
color images.  One approach would be to convert RGB to HSL,
stretch the L (lightness) data to give L', and then convert HSL'
to R'G'B'   I've experimented with this but don't have any examples
in my Computer Lab about this yet.

--
efg

Earl F. Glynn     E-Mail:  EarlGl...@att.net
Overland Park, KS  USA

efg's Computer Lab:  http://www.efg2.com/Lab

Re:JPG: resize, brightness, contrast ?


Try this from Gordy @ G-SOFT - It was posted here last week.

function ContrastLUT(Amount: Integer): array[Byte]of Byte;
var
  i,z: Integer;
begin
  for i:=0 to 126 do
  begin
    z:=i-((Abs(128-i)*Amount)div 256);
    if z>255 then z:=255 else if z<0 then z:=0;
    Result[i]:=z;
  end;
  for i:=127 to 255 do
  begin
    z:=i+((Abs(128-i)*Amount)div 256);
    if z>255 then z:=255 else if z<0 then z:=0;
    Result[i]:=z;
  end;
end;

apply the lookup table to your bitmap bytes to adjust contrast

Regards Paul

Re:JPG: resize, brightness, contrast ?


Quote
"Paul Claridge" <paul.clari...@{*word*269}.net> wrote in message

news:833ftl$8td9@forums.borland.com...

Quote
> Try this from Gordy @ G-SOFT - It was posted here last week.

> function ContrastLUT(Amount: Integer): array[Byte]of Byte;
...
> apply the lookup table to your bitmap bytes to adjust contrast

If I'm reading this fragment correctly, this function returns a 256-byte
lookup table that makes darker intensities (those < 127) darker, and lighter
intensities (those > 127) lighter.  This lookup table should work fine for a
grayscale image with a median value around 127.   But this may
or may not be appropriate for any given grayscale image.  And the code
doesn't address how it might be applied to pixel data in scanlines,
or when a palette is used, or when you have a JPEG image.

What if the grayscale median were about 50?  I don't think this technique
and lookup table will work so well.  For a grayscale image, histogram
stretching (or histogram equalization) would work fairly well.  Take a look
at the image in this Lab Report that has a median grayscale value of 49
and how it is histogram stretched from a range of 11..97 to the full-contrast
range of 0..255:
http://www.efg2.com/Lab/ImageProcessing/HistoStretchGrays.htm

You can't just apply the lookup table in the fragment, or in histogram
stretching, to each of the three RGB color planes separately and
always get good results.  While this  might work in some images,
it can (and does) introduce color shifts in other images.

--
efg

Earl F. Glynn     E-Mail:  EarlGl...@att.net
Overland Park, KS  USA

efg's Computer Lab:  http://www.efg2.com/Lab

Re:JPG: resize, brightness, contrast ?


The Envision Library supports brightness and constrast transforms, by
converting from RGB to HSL color space, performing the transform in HSL,
then converting back to RGB. It's not the fastest implementation, but it
may be helpful for you.

Best regards,

Michel
------
http://www.intervalsoftware.com
Envision Image Library
Spider Object Database
Spider Container and Persistent Classes  (freeware)
WordShare string localization  (freeware)

Quote
Tom Brendl wrote:

> How to load, resize and save JPG images in my app (D5) ?
> I must often resize many and many JPG photos and sometimes change their
> brightness and contrast...
> Many thanx for any help, link, unit, component,...
> Tom

Re:JPG: resize, brightness, contrast ?


Quote
"Earl F. Glynn" wrote:
> One approach would be to convert RGB to HSL,
> stretch the L (lightness) data to give L', and then convert HSL'
> to R'G'B'

Hi Earl!

I don't have any experience with HSL. Can I assume the L is equivalent
to the L in Lab? So histogram stretching would just as well work in Lab?

Thanks,

Joris

Other Threads