Log in

View Full Version : Why this script does not output an image very close to the input? ImageWriter


cagali
3rd July 2015, 12:20
String file = "input.jpg"

ImageSource(file)
ImageWriter(file = "R:\out", start = 1, end = 1, type = "jpg")

__film = last
__t0 = __film.trim(1, 1)
__t0


I want to get an image exactly very close to the input.
However, I get one with a little bit wrong color.

I have the script run in mpc and potplayer.
Both give the same result.

What is missed in the script?
Thank you very much.

colours
3rd July 2015, 13:08
JPEG uses YCbCr internally, and the conversions to and from RGB both introduce some rounding error, which can manifest as a slight discolouration.

fvisagie
3rd July 2015, 13:27
My guess as to the cause is JPG being a lossy compression method. I.e., your input was re-encoded and thus altered when written to JPG.

A more meaningful test would be to use uncompressed or losslessly compressed output formats, e.g. BMP:
String file = "input.bmp"
original = ImageSource(file)
writerout = original.ImageWriter(file = "R:\out", start = 0, end = -1, type = "bmp")
written = ImageSource("R:\out%06d.bmp")
StackHorizontal(Compare(original, writerout), Compare(original, written))


EDIT: And what Colours said :)

cagali
3rd July 2015, 18:36
JPEG uses YCbCr internally, and the conversions to and from RGB both introduce some rounding error, which can manifest as a slight discolouration.

My guess as to the cause is JPG being a lossy compression method. I.e., your input was re-encoded and thus altered when written to JPG.

A more meaningful test would be to use uncompressed or losslessly compressed output formats, e.g. BMP:
String file = "input.bmp"
original = ImageSource(file)
writerout = original.ImageWriter(file = "R:\out", start = 0, end = -1, type = "bmp")
written = ImageSource("R:\out%06d.bmp")
StackHorizontal(Compare(original, writerout), Compare(original, written))


EDIT: And what Colours said :)

Thank you gentlemen.

I modified the script to read and write in BMP only.
Now the output bmp is identical to the input, verified using "compare" function of ImageMagick.

And about the colors that go wrong using jpeg, the most noticable ones are those near bright pink.