Page 1 of 5

Correcting tile luminance and/or color differences?

Posted: 2017-01-25T18:15:28-07:00
by ProGamer
The way I process the individual tiles sometimes creates a slight difference in luminance/color between the tiles. This difference makes it impossible to blend the tiles together.

This image: https://i.imgur.com/Wa9v2Cb.jpg, is composed of 4 tiles: https://imgur.com/a/fXxjO

My code is in this project here: https://github.com/ProGamerGov/Neural-Tile and I recently posted an issue (solved) relating to my tiling project here: https://www.imagemagick.org/discourse-s ... =1&t=31221

So my question is, can ImageMagick correct the difference between the tiles? And if so, how?

Re: Correcting tile luminance and/or color differences?

Posted: 2017-01-25T18:45:24-07:00
by snibgo
It looks as if there is a known area of overlap between pairs of images. Is that correct?

If so, there are a number of methods you can use:

1. Simply composite them together with no transition. This gives obvious hard boundaries.

2. Apply an alpha blending at each overlap, a linear (or non-linear) fade. This seem to be what your "This image" has.

3. Apply a gain-and-bias method so make the overlap of one image look like the corresponding area of the other. Apply the same G&B to the entire image, or blend the effect across the image, or whatever you want. See my "Gain and bias" page.

4. Equalize histograms of overlaps. This is similar to G&B, but more complex, but the results may be better. See my "Process Modules" page.

5. Apply a Poisson editing technique to get each blend. This gives great results, but is quite complex. It applies a gradual change across the entire image, rather than just the overlap area. Not for the faint-hearted. See my "Seamless photomontage" page.

6. Don't blend it - cut it. That is, make an irregular cut within the overlap region, where the difference between the overlapping images is a minimum. Aka "Minimum Error Boundary Cut". See my "Rectangle boundaries with dark paths" and related pages.

Re: Correcting tile luminance and/or color differences?

Posted: 2017-01-25T19:05:32-07:00
by snibgo
snibgo wrote:It looks as if there is a known area of overlap between pairs of images. Is that correct?
Ah, no, that's not correct. There are approximate overlaps, but they are merely similar, not the same. I doubt that any automated method will give a "perfect" result.

Re: Correcting tile luminance and/or color differences?

Posted: 2017-01-25T19:08:15-07:00
by ProGamer
snibgo wrote: 2017-01-25T19:05:32-07:00
snibgo wrote:It looks as if there is a known area of overlap between pairs of images. Is that correct?
Ah, no, that's not correct. There are approximate overlaps, but they are merely similar, not the same. I doubt that any automated method will give a "perfect" result.
The overlaps are exact? The only difference is that I had to resize the overlap values to match the new tile sizes, but my script still automatically keeps track of and calculates the overlap value.

Re: Correcting tile luminance and/or color differences?

Posted: 2017-01-25T19:52:45-07:00
by snibgo
The right-hand 96 columns of your fourth image are similar to the left-hand 96 columns of your first.

Code: Select all

%IM%convert til004.png -gravity East -crop 96x+0+0 +repage til_x4.png

%IM%convert til001.png -gravity West -crop 96x+0+0 +repage til_x1.png
til_x4:
Image
til_x1:
Image
Look at the fold of the blue cloth near the top of each. They are similar, but different.

We can make a composite of these two overlaps, using the left part of til_x4 and the right part of til_x1.

Code: Select all

call %PICTBAT%rectDp til_x4.png til_x1.png til_x41.png 100 0 0 0
Image
This result, til_x41.png, can be used as the overlap.

(Windows BAT scripts. All images converted to jpg for the web.)

Re: Correcting tile luminance and/or color differences?

Posted: 2017-01-25T22:16:26-07:00
by ProGamer
snibgo wrote: 2017-01-25T19:05:32-07:00
snibgo wrote:It looks as if there is a known area of overlap between pairs of images. Is that correct?
Ah, no, that's not correct. There are approximate overlaps, but they are merely similar, not the same. I doubt that any automated method will give a "perfect" result.
Would it be possible to take the luminance/color from the first tile, and apply it to the other 3 tiles?

Re: Correcting tile luminance and/or color differences?

Posted: 2017-01-25T22:42:58-07:00
by snibgo
I would do it by overlaps. The top-left and top-right images, til_004 and til_001, overlap. Find what luminance and colour shift is needed to the overlapping part of til_004 to make it match the same part of til_001, and apply that shift to the entire image.

Code: Select all

setlocal enabledelayedexpansion

call %PICTBAT%meanSdTr til_x4.png til_x4_
call %PICTBAT%meanSdTr til_x1.png til_x1_

call %PICTBAT%calcGainBias til_x4_ til_x1_ tx_4_

%IM%convert ^
  til004.png ^
  -channel R -function Polynomial !tx_4_gain_R!,!tx_4_bias_R! ^
  -channel G -function Polynomial !tx_4_gain_G!,!tx_4_bias_G! ^
  -channel B -function Polynomial !tx_4_gain_B!,!tx_4_bias_B! ^
  +channel ^
  til004b.png

endlocal
til004b is now a version of the top-left image that is a close match to til001.png, the original top-right. It isn't perfect but is much closer than it was.

Then composite those together:

Code: Select all

%IM%convert ^
  til004b.png ^
  ( til001.png -repage +1824+0 ) ^
  -compose Over -layers merge ^
  t41.png
The join is visible, but not bad. The MEBC method with rectDp I showed above would reduce that.

That add the third image to the first two, then the fourth to the first three.

A script could be written to take any number of images, with their offsets, and combine them in this way.

Re: Correcting tile luminance and/or color differences?

Posted: 2017-01-25T22:45:24-07:00
by fmw42
Would it be possible to take the luminance/color from the first tile, and apply it to the other 3 tiles?
This comment is out of context, since I do not know your images nor what the other tiles look like. But snibgo has some code to adjust the brightness and contrast (via mean and standard deviation) of one image to match that of another. I have a bash unix shell script, transfercolor, that will transfer the color of one image to that of another in a similar way in LAB colorspace. It seems to work a little better than in RGB. We both have scripts that match the histogram of one image to that of the other. See my web site link below.

P.S. snibgo, we must have been posting at the same time. You can try your code above in LAB. It is essentially what I do in my script.

Re: Correcting tile luminance and/or color differences?

Posted: 2017-01-25T22:51:41-07:00
by fmw42
P.S. If the two images are identical in shapes (i.e. registered), then one could just do -compose colorize to tranfser the color of one image to its similar looking image. That does not work, however, for completely different images

Re: Correcting tile luminance and/or color differences?

Posted: 2017-01-25T22:59:51-07:00
by ProGamer
snibgo wrote: 2017-01-25T22:42:58-07:00 I would do it by overlaps. The top-left and top-right images, til_004 and til_001, overlap. Find what luminance and colour shift is needed to the overlapping part of til_004 to make it match the same part of til_001, and apply that shift to the entire image.

Code: Select all

setlocal enabledelayedexpansion

call %PICTBAT%meanSdTr til_x4.png til_x4_
call %PICTBAT%meanSdTr til_x1.png til_x1_

call %PICTBAT%calcGainBias til_x4_ til_x1_ tx_4_

%IM%convert ^
  til004.png ^
  -channel R -function Polynomial !tx_4_gain_R!,!tx_4_bias_R! ^
  -channel G -function Polynomial !tx_4_gain_G!,!tx_4_bias_G! ^
  -channel B -function Polynomial !tx_4_gain_B!,!tx_4_bias_B! ^
  +channel ^
  til004b.png

endlocal
til004b is now a version of the top-left image that is a close match to til001.png, the original top-right. It isn't perfect but is much closer than it was.

Then composite those together:

Code: Select all

%IM%convert ^
  til004b.png ^
  ( til001.png -repage +1824+0 ) ^
  -compose Over -layers merge ^
  t41.png
The join is visible, but not bad. The MEBC method with rectDp I showed above would reduce that.

That add the third image to the first two, then the fourth to the first three.

A script could be written to take any number of images, with their offsets, and combine them in this way.
I understand now what you meant by your previous comment, my bad. My script uses bash/shell, but it should be simple enough to convert a version the code you posted in your comment, seeing as ImageMagick doesn't seem to have many differences in the names of things between languages? Or maybe I could try Fred's method?

Anyways, I'll try out the proposed solution tomorrow. I know there is nothing other than some specialized neural network that could perfectly put the two together while making sure the tiles share a similar histogram (I think that's the right term for what I am trying to do?), but at the moment anything would be better than nothing. Thanks for the help!

Re: Correcting tile luminance and/or color differences?

Posted: 2017-01-25T23:22:27-07:00
by ProGamer
fmw42 wrote: 2017-01-25T22:45:24-07:00
Would it be possible to take the luminance/color from the first tile, and apply it to the other 3 tiles?
This comment is out of context, since I do not know your images nor what the other tiles look like. But snibgo has some code to adjust the brightness and contrast (via mean and standard deviation) of one image to match that of another.
I shared Imgur links to an example of the problem in the first part of my post, which has occurred with many of my tiled images. I used imgur because I think the images may be too big for this forum at 1920x1288 for each tile and a final tiled image size of 3743x2497. I used Imgur because it's known for being more reputable than other image hosting sites.

But here is the image with all the tiles combined: https://i.imgur.com/Wa9v2Cb.jpg

You can see both the right side tiles are brighter than the two tiles on the left, with the bottom right being more bright than the top right tile. The two tiles on the left seem to be similar enough in brightness that no difference between them is visible.
fmw42 wrote: 2017-01-25T22:45:24-07:00 I have a bash unix shell script, transfercolor, that will transfer the color of one image to that of another in a similar way in LAB colorspace. It seems to work a little better than in RGB. We both have scripts that match the histogram of one image to that of the other. See my web site link below.
I'll take a look at your transfer color script, but in the past I have found it hard to isolate the functions that your scripts perform. This is an issue with my knowledge of programming/coding and my abilities, as your code seems to be extremely well written and not the fault of you or anyone else.

Re: Correcting tile luminance and/or color differences?

Posted: 2017-01-25T23:24:23-07:00
by fmw42
Sometimes histogram matching does not do well compared to the linear brightness contrast method. You should try both. If on Unix, you can try my histmatch and transfercolor scripts. If on Windows, then snibgo has similar scripts.

Re: Correcting tile luminance and/or color differences?

Posted: 2017-01-25T23:27:14-07:00
by fmw42
I am not sure I understand your image. I take it from your first post above that it is made up of 4 tiles. I assume they overlap some amount? I do not see an corresponding overlay from the left side to the right. Also there seems to be a blurry transition in the middle. Can you clarify?

Re: Correcting tile luminance and/or color differences?

Posted: 2017-01-26T09:53:25-07:00
by ProGamer
fmw42 wrote: 2017-01-25T23:24:23-07:00 Sometimes histogram matching does not do well compared to the linear brightness contrast method. You should try both. If on Unix, you can try my histmatch and transfercolor scripts. If on Windows, then snibgo has similar scripts.
I tried your transfercolor script and it did not seem to have an effect on the tiles.

Re: Correcting tile luminance and/or color differences?

Posted: 2017-01-26T09:58:36-07:00
by ProGamer
fmw42 wrote: 2017-01-25T23:27:14-07:00 I am not sure I understand your image. I take it from your first post above that it is made up of 4 tiles. I assume they overlap some amount? I do not see an corresponding overlay from the left side to the right. Also there seems to be a blurry transition in the middle. Can you clarify?
Yes, the image is made up of 4 tiles. The original image was run through a neural network before it was chopped into overlapping tiles. The individual tiles were then run through the neural network again, which increased their quality and size. The issue is however that the neural network has some drift in terms of brightness/content/style/color between the original tile and the processed tile. I am unable to correct the neural network aspect of the tiling process, but I am seeking to correct things after the fact. The tiling process is done to create a higher quality image than current GPU hardware will allow (the image I linked to, took 12GB of GPU ram to make).