fehlfarbe / gimp2acv

Converts GIMP curves to Adobe ACV curves
7 stars 3 forks source link

Photoshop acv output differs significantly from GIMP output #2

Open PacoH opened 11 months ago

PacoH commented 11 months ago

Original file:

arthurrackhamtre00rack_0018.jpg arthurrackhamtre00rack_0018 w=400 px

GIMP reference file using arthurrackham.gcv [arthurrackham.gcv.zip] exported curve file:

arthurrackhamtre00rack_0018.gimp.arthurrackham.gcv.jpg arthurrackhamtre00rack_0018 gimp arthurrackham gcv w=400 px

Photshop file created using online Photoshop app Photopea | Online Photo Editor using gimp2acv generated arthurrackham.acv [arthurrackham.acv.zip] curve file:

arthurrackhamtre00rack_0018.photopea.arthurrackham.acv.jpg arthurrackhamtre00rack_0018 photopea arthurrackham acv w=400 px

File created using Fred's ImageMagick Scripts: CURVES operating on points extracted from the arthurrackham.gcv exported curve file to arthurrackham.gcv.im [arthurrackham.gcv.im.zip] (very difficult and time-consuming):

arthurrackhamtre00rack_0018.imcurves.255.jpg arthurrackhamtre00rack_0018 imcurves 255 w=400 px

Image Similarity Comparison

Using imagemagick's magick compare function to determine the similarity between the original GIMP image and the CURVES-generated image:

NCC between arthurrackhamtre00rack_0018.gimp.arthurrackham.gcv.jpg and arthurrackhamtre00rack_0018.imcurves.255.jpg is 0.999801

Where NCC is the 'normalized cross correlation' metric, where two images are considered similar when their normalized cross correlation is 1.

imgappendsxs w=800 px

Using the magick compare function to determine the similarity between the original GIMP-generated image and the Photoshop image with the gimp2acv-generated arthurrackham.acv curve file:

NCC between arthurrackhamtre00rack_0018.gimp.arthurrackham.gcv.jpg and arthurrackhamtre00rack_0018.photopea.arthurrackham.acv.jpg is 0.996877

This may not sound like a big difference but it is very noticeable if you visually compare the two images.

imgappendsxs w=800 px

fehlfarbe commented 11 months ago

Hi!

Thanks for the detailed description! It's been a while since I wrote this code but if I remember correctly the problem is that GIMP and Photoshop uses different curves so when I just extract the points used in GIMP to the ACV file, the curves and the result will be very different like this:

grafik (Photoshop on the left, GIMP on the right with a Photoshop curve based on the points from GIMP)

The GIMP curves file also contains the samples from 0...255 so it would be very simple to just create 256 curve points for the ACV file. Unfortunately the ACV standard is limited to 19 points per curve (see: https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#50577411_pgfId-1056330 ) That's why I try to fit the curve with 16 points (I don't know why I'm not using the maximum 19 points, see: https://github.com/fehlfarbe/gimp2acv/blob/71b351a0ba875bc5f33e8d1ffc7fe9763c3f8582/acv.py#L75-L85 Which results in this curve:

grafik

Maybe I will have some time in the next days to find a better algorithm to interpolate the curve.

PacoH commented 11 months ago

Thanks for the detailed reply.

Did you take a look at Fred's ImageMagick Scripts: CURVES? You can download the script Download Script and take a look at what he does.

It uses a quoted string of x,y pairs "x1,y1 x2,y2 ..."

List of x,y break-points for the curved transformation where x,y values can range from 0 to xscale,yscale break point values of piece-wise linear transformation enclosed in quotes minimum of one (x,y) break point pair x corresponds to the graylevel in the input image y corresponds to the graylevel in the outut image x,y non-negative floats enclosed in quotes

or a text file containing a list of break points, one x,y pair per line

The range of values for x,y breakpoint pairs from 0 to xscale,yscale, positive integers default=100,100

It uses 86 break points in total. A GIMP curve has 255 separate points.

This is what I used with a scale of 255. Either scale gives identical results.

I have a somewhat complicated way of getting the points from a GIMP curves file. More on that soon.

fehlfarbe commented 11 months ago

I tried to get generate better curve points from the samples via Lagrange interpolation. Can you checkout this branch?

https://github.com/fehlfarbe/gimp2acv/tree/langrange_interpolation

grafik

Fred's ImageMagick script seems more simple because he can use more points and cubic Bezier splines which are simple curves connected to each other but the Photoshop acv files are limited to 16 points and use a Lagrange curve to connect all points. Lagrange curves are known for "overshooting", I think it's called "Runge's phenomenon", that's why it's so hard to convert GIMP curves to acv curves...besides, my computer graphics lectures were already some years ago :sweat_smile:

PacoH commented 11 months ago

Thanks! I tried it and it works well.

imgappendsxs

NCC between arthurrackhamtre00rack_0018.gimp.arthurrackham.gcv.jpg and arthurrackhamtre00rack_0018.arthurrackham.gimp2acv.py.acv.jpg is 0.999332

PacoH commented 11 months ago

I also found this:

vbalnt/filterizer: Python script to extract image filters from photoshop .acv files The code reads a .acv file and outputs the polynomials that adjust the colours of an image. There polynomials can then be used to produce filters for images in every language you prefer.

It refers to this very useful tool:

Python filtering example Github user @pfdevilliers has wrapped together a nice python script using the curve reading code above. Take a look here.

filter.py Python script that reads the photoshop curve (.acv) files, extract the polynomials and applies it to an image.

Usage: python filter.py <path-to-curve-file> <path-to-image-file>

I compared the result with the Photopea result and got: NCC between Photopea arthurrackham.gimp2acv.jpg and filter.py arthurrackham.gimp2acv.py.acv.jpg is 0.999808

imgappendsxs