Page 1 of 1
lossy compression or lossless compression?
Posted: 2012-11-29T01:34:27-07:00
by jasonlee
Q1: When using ResizeImage() func, will there be quality loss?
Q2: When convert an image from png(or gif) format to jpg format, can it cause some question about quality loss?
IM Version: ImageMagick 6.7.8-3 2012-09-11 Q16
MagickCore API
Q1:
Code: Select all
Image *zoomimage = ResizeImage(image, width, height, LanczosFilter, 1.0, exception);
if (exception->severity != UndefinedException || zoomimage == (Image *) NULL)
{
if (DEBUG_FLAG)
{
printf("ResizeImage() failed.\n");
}
break;
}
Q2:
Code: Select all
image_info = CloneImageInfo((ImageInfo *) NULL);
image = BlobToImage(image_info, inputblob, len, exception);
...
strcpy(image_info->magick, "jpg");
outputblob = ImagesToBlob(image_info, thumbnails, &len,exception);
Re: lossy compression or lossless compression?
Posted: 2012-11-29T11:07:02-07:00
by fmw42
Any conversion to jpg, even with -quality 100, will cause some loss of quality. JPG is a lossy compression format. If you want lossless, then you could use JP2000.
Re: lossy compression or lossless compression?
Posted: 2012-12-02T19:25:13-07:00
by jasonlee
fmw42 wrote:Any conversion to jpg, even with -quality 100, will cause some loss of quality. JPG is a lossy compression format. If you want lossless, then you could use JP2000.
Thanks. But I want to make sure wether it will cause some loss of quality to convert to png or gif.
Othermore, wether there are some loss of quality when resizing a picture (such as zoom a picture from 800*600 to 400*300) ?
Thanks for your clearation.
Re: lossy compression or lossless compression?
Posted: 2012-12-02T20:23:56-07:00
by fmw42
Conversion to PNG should not lose quality if you use 24bit color PNG. Conversion to GIF may because it is limited to 256 colors.
see
http://www.imagemagick.org/Usage/formats/#gif
http://www.imagemagick.org/Usage/formats/#png
Changes is quality can happen when you resize. But IM has numerous filters to mitigate that.
see
http://www.imagemagick.org/Usage/resize/
http://www.imagemagick.org/Usage/filter/
http://www.imagemagick.org/Usage/filter/nicolas/
Re: lossy compression or lossless compression?
Posted: 2012-12-03T04:53:48-07:00
by snibgo
jasonlee wrote:Thanks. But I want to make sure wether it will cause some loss of quality to convert to png or gif.
What exactly do you mean by "quality"? If you remove bits from pixels, you lose information. This may or may not be visible in the result. If you will be further processing the result, it's best to keep all the data you can. When saving to PNG, IM sometimes needs to be told to save it as PNG24 to keep all the detail.
jasonlee wrote:Othermore, wether there are some loss of quality when resizing a picture (such as zoom a picture from 800*600 to 400*300) ?
Again, you will obviously lose data. In this case, 75% of the data.
EDIT: I meant "PNG24" not "PNG16".
Re: lossy compression or lossless compression?
Posted: 2012-12-03T23:45:54-07:00
by anthony
There will always be some loss of quality when resizing. but it is not a matter of simply loosing pixel data, but of merging the pixel data. When enlarging you actually generate more data, but the quality will not be quite perfect either, at least not without making an ugly blocky image!
Halving the dimensions will cause ALL the information to be merged into a quarter the amount of space. All the information is there but you loose the finer details (or the higher spatial frequencies in expert terms) as pixels become merged. When images are resized by non-integer amounts, you also get a loss of quality from having to map a array of values into a completely different array of values, and that can generate other 'artefacts' that may or may not be wanted.
To do this resize (or distort) will try to map a function, surface, or waveform to the input image array, so as try to best determine what the output values to match that same function, surface, waveform. This is what filters are -- attempts to try and match a 'interpolatory' surface to the input image to generate an output image using a different array of values.
Now when coding, it is not looked at like that, but as a 'pixel contribution' or 'neighbourhood weighted average' or even a 'convolution' of nearby pixels values (samples) to try and generate the best pixel values. This 'sampling function' is called a 'reconstruction filter', or just 'filter'.
There is a loss of quality, and how sharp, or how many other 'artefacts' are introduced by this process is what makes resizing so difficult. However I would not say you loss data, just merge data. How much quality is lost. Well that is very very difficult to determine without some specific definitions.
See IM examples, resize and filter sections.