问题
I am trying to perform the DCT on an image with block size 8X8 in java. After performing DCT on the first block, I get the very first value as "372". After performing the DCT on the entire image, I wrote the values into a PNG-grayscale image.Values inside the image automatically changed. The grayscale image will not store the value greater than 255. What will happen to the value which is greater than 255 (for eg., 372) ?
回答1:
you can not get to original image after loss of information so you need to:
- perform DCT or what ever
- find
min,max
values from whole image - change range so any
pixel(x,y)=(255*(pixel(x,y)-min))/(max-min)
+/-1
or some if to clamp to the right range
After this you lose absolute values but the relative changes stays there
- for some purposes is this enough
- if you need to restore the original image
- then you need to encode min,max values to the
png
somewhere - so add a dummy scanline(s) and encode
min,max
into first few pixels ...
restoration is then easy:
- read
png
image - decode min,max
- restore original dynamic range
pixel(x,y)=min+(((max-min)*pixel(x,y))/255)
+/-1
or some if to clamp to the right range
- perform IDCT or what ever
来源:https://stackoverflow.com/questions/31230588/what-is-the-effect-of-storing-a-larger-value-in-a-grayscale-png-image