It is currently Mon Jul 22, 2024 12:29 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Inpainting without interpolation?
PostPosted: Tue Dec 03, 2013 6:03 pm  (#1) 
Offline
GimpChat Member

Joined: Dec 03, 2013
Posts: 10
I have a simple GIF of a few colors. Using G'MIC's inpaint (from the command line) with a mask of the color I wish to remove works quite well. However, interpolation/anti-aliasing (blending? not sure what the right term here is) causes intermediary pixels of a different color to appear between pixels. Is there a way to disable this kind of interpolation so that additional colors are not added to my image?

Thanks!


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Inpainting without interpolation?
PostPosted: Tue Dec 03, 2013 6:55 pm  (#2) 
Offline
GimpChat Member

Joined: Dec 03, 2013
Posts: 10
Here is an example:

Image

Original image, mask, output

gmic shapes.png mask.png --inpaint[-2] [-1] -remove[-2] -output out.png

I'm wondering if there is a way to prevent it from "guessing" colors and use only those available in the original (or specify a set of "allowed" colors).

Image


Top
 Post subject: Re: Inpainting without interpolation?
PostPosted: Wed Dec 04, 2013 4:06 am  (#3) 
Offline
GimpChat Member
User avatar

Joined: Jan 03, 2011
Posts: 1656
I guess that Patch-based inpainting should work better here. Give a try to command '-repair' then.


Top
 Post subject: Re: Inpainting without interpolation?
PostPosted: Wed Dec 04, 2013 4:41 am  (#4) 
Offline
GimpChat Member

Joined: Apr 12, 2010
Posts: 5870
Of course in the plugin you will NOT find -repair

But with the plugin you may go to Various>Custom Code and there use commands as -repair

_________________
My 3D Gallery on Deviantart http://photocomix2.deviantart.com/
Main gallery http://www.flickriver.com/photos/photocomix-mandala/
Mandala and simmetry http://www.flickriver.com/photos/photocomix_mandala/

Image

Mrs Wilbress


Top
 Post subject: Re: Inpainting without interpolation?
PostPosted: Wed Dec 04, 2013 5:00 am  (#5) 
Offline
GimpChat Member
User avatar

Joined: Jan 03, 2011
Posts: 1656
PhotoComiX, the original poster does use the command line. And it is cool because G'MIC is not only a plug-in for GIMP !
So, please let him use the command line if he'd like to :)


Top
 Post subject: Re: Inpainting without interpolation?
PostPosted: Wed Dec 04, 2013 6:51 am  (#6) 
Offline
GimpChat Member

Joined: Apr 12, 2010
Posts: 5870
i beg you pardon, i did not known, for sure was not my intention discourage use of command line gmic

_________________
My 3D Gallery on Deviantart http://photocomix2.deviantart.com/
Main gallery http://www.flickriver.com/photos/photocomix-mandala/
Mandala and simmetry http://www.flickriver.com/photos/photocomix_mandala/

Image

Mrs Wilbress


Top
 Post subject: Re: Inpainting without interpolation?
PostPosted: Wed Dec 04, 2013 1:56 pm  (#7) 
Offline
GimpChat Member

Joined: Dec 03, 2013
Posts: 10
Thanks for the tip! -repair does do a better job for the example I posted (although it creates some artifacts), but I'm actually working with a much more complicated image. I'll see if I can get a better example together. The -inpaint feature just works SO well. I tried OpenCV's inpaint function and it was terrible in comparison.

I've looked at the G'MIC source, and it appears there are some 'blend' parameters that could possibly be turned down to 0. Unfortunately, I'm not sure if this is what is causing the pixel interpolation (or even where exactly the command line tool calls the inpaint function). I'm going to see if I can extend the -inpaint functionality to support additional parameters for blending/interpolation if possible. Any gentle nudges in the right direction would be greatly appreciated!

I'll try to get a better example uploaded. Thanks again!


Top
 Post subject: Re: Inpainting without interpolation?
PostPosted: Thu Dec 05, 2013 5:19 pm  (#8) 
Offline
GimpChat Member

Joined: Dec 03, 2013
Posts: 10
Ok, time for a proper example!

Attachment:
Screen Shot 2013-12-05 at 4.06.02 PM.png
Screen Shot 2013-12-05 at 4.06.02 PM.png [ 42.79 KiB | Viewed 3924 times ]


This works EXTREMELY well as you can see. I just want to disable the pixel smoothing seen here:

Image

Could inpaint_flow possibly help me? I haven't had much luck getting it to work.

Is this the function solely responsible for inpainting?

CImg<T>& inpaint(const CImg<t>& mask) {


Top
 Post subject: Re: Inpainting without interpolation?
PostPosted: Fri Dec 06, 2013 4:39 am  (#9) 
Offline
GimpChat Member
User avatar

Joined: Jan 03, 2011
Posts: 1656
Well, using command -repair with a patch size of 3 and blending disabled, I get this :

Attachment:
gmic_inpaint.png
gmic_inpaint.png [ 27.66 KiB | Viewed 3897 times ]


which seems to be what you are looking for.
There are several inpaint algorithms in G'MIC, so you need to be aware of which is the best to use in your case (-repair here).
There are basically :

* -inpaint : you know it, it is very fast but does pixel averaging, so no way you can avoid new color shades appearing.
* - repair : a more sophisticated (and slower) patch-based inpainting algorithm. As it works basically with copy/pasting known patches to the locations of the inpainting mask, it is able to preserve exactly the original colors.
* -inpaint_flow : a PDE-based method for inpainting. Here again, you will get a smoother reconstruction (which is not what you want).


Top
 Post subject: Re: Inpainting without interpolation?
PostPosted: Thu Feb 20, 2014 7:23 pm  (#10) 
Offline
GimpChat Member

Joined: Dec 03, 2013
Posts: 10
The results of the inpaint function really worked best for me. I wrote an extremely naive algorithm in python to normalize to a specified set of colors after some slight anti-aliasing has occurred. It works for very simple rasters like the types above. I have no idea how it would work on a photo, but it has worked on millions of simple images. It requires the "pillow" spin-off of the Python Image Library (PIL).

The script takes an image followed by a comma-delimited list of hex values as input. Quite primitive, I know :)

OK: both linking to the code and putting it in the post gives me "Your post looks too spamy for a new user, please remove off-site URLs." so I will share when I am able.

Update: ok, it let me post it!

#! /usr/bin/python

import os, sys
from PIL import Image
from collections import Counter

filename = sys.argv[1]
img = Image.open(filename)
im = img.load()

width, height = img.size

colorsin = sys.argv[2].split(',')


def hex_to_rgb(value):
    value = value.lstrip('#')
    lv = len(value)
    return tuple(int(value[i:i+lv/3], 16) for i in range(0, lv, lv/3))


colors = []

for color in colorsin:
    colors.append(hex_to_rgb(color))


def is_valid(c, max):
    "Ensure that pixel coordinate is not out of range of the image"
    if (c >= 0 and c < max):
        return True
    else:
        return False


def neighbor_pixels(x,y):
    "Find all valid neighboring pixels"
    neighbors = []
    for dx in range(-1,2):
        for dy in range(-1,2):
            tempx = x + dx
            tempy = y + dy
            if (is_valid(tempx, width) and is_valid(tempy, height)):
                neighbors.append([tempx, tempy])
    return neighbors
   

def calc_color(x,y):
    "Find the most commonly occuring valid color in neighboring pixels"
    cnt = Counter()
    neighbors = neighbor_pixels(x,y)
    for neighbor in neighbors:
        temp_image = im[neighbor[0],neighbor[1]]
        if temp_image in colors:
            cnt[temp_image] +=1
    try:
        return cnt.most_common(1)[0][0]
    except IndexError:
        print neighbor[0],neighbor[1],x,y
        print 'INDEX ERROR'
        return (0,0,0)


y = 0
while y<height:
    x = 0
    while x<width:
        if im[x,y] not in colors:
            im[x,y] = calc_color(x,y)
        x = x+1
    y = y+1


newfile = filename.partition('.')
newfile = newfile[0] + "-clean.png"

img.save(newfile)


Top
 Post subject: Re: Inpainting without interpolation?
PostPosted: Fri Feb 21, 2014 11:51 am  (#11) 
Offline
GimpChat Member
User avatar

Joined: Jan 03, 2011
Posts: 1656
You made me think a little bit about the 'simple' inpainting method used in G'MIC, and indeed, there are some things we can improve.
I will add some new inpainting modes that allows to have less interpolated (median) and more interpolated (high-connexity averaging) inpainting modes.
The function will be also extended to deal with 3d volumetric images as well (work only for 2d images right now).
It should be available in the next release (numbered 1.5.8.4).


Top
 Post subject: Re: Inpainting without interpolation?
PostPosted: Fri Feb 21, 2014 12:50 pm  (#12) 
Offline
GimpChat Member

Joined: Sep 24, 2012
Posts: 275
Location: Scotland
Also on the subject of inpainting... not sure if you saw my other post about it (apologies if you did) but is there any chance of loop increment control being added back to patch based inpaint? It really helps for some of my filters!

If not I promise to stop nagging now :oops:


Top
 Post subject: Re: Inpainting without interpolation?
PostPosted: Fri Feb 21, 2014 1:04 pm  (#13) 
Offline
GimpChat Member
User avatar

Joined: Jun 02, 2013
Posts: 2075
Is there a good tutorial about how to use this feature? Thanks.

_________________
Image


Top
 Post subject: Re: Inpainting without interpolation?
PostPosted: Fri Feb 21, 2014 1:17 pm  (#14) 
Offline
GimpChat Member

Joined: Dec 03, 2013
Posts: 10
From within GIMP or from the CLI?


Top
 Post subject: Re: Inpainting without interpolation?
PostPosted: Fri Feb 21, 2014 3:37 pm  (#15) 
Offline
GimpChat Member
User avatar

Joined: Jan 03, 2011
Posts: 1656
dboze : from both interfaces of course.
garagecoder: O, I've heard you, this is something I'll probably put back in the next version too :)


Top
 Post subject: Re: Inpainting without interpolation?
PostPosted: Fri Feb 21, 2014 4:01 pm  (#16) 
Offline
GimpChat Member

Joined: Sep 24, 2012
Posts: 275
Location: Scotland
:yes

This is really great news :cool
And I have loooots of time for a bit now so plan to finally start some stuff on the wiki about inpainting


Top
 Post subject: Re: Inpainting without interpolation?
PostPosted: Sat Feb 22, 2014 5:50 am  (#17) 
Offline
GimpChat Member
User avatar

Joined: Jan 03, 2011
Posts: 1656
garagecoder, I'm done with the changes in the source code for all the stuffs you've asked me in this thread :)
So, I will start to build new beta packages, they should be available in one hour or so (only for Linux, for now)
If you want to play with it, please tell me if that is alright for you. Thanks.


Top
 Post subject: Re: Inpainting without interpolation?
PostPosted: Sat Feb 22, 2014 7:50 am  (#18) 
Offline
GimpChat Member

Joined: Sep 24, 2012
Posts: 275
Location: Scotland
Got it now thanks :yup
I see increment added in after factor, building the command line gmic to try it out :lick

*edit*
OK after some quick testing... it's perfect! :jumpclap
It's now possible to get even better results as well as keeping it quite fast (depending on the purpose of course).


Top
 Post subject: Re: Inpainting without interpolation?
PostPosted: Sat Feb 22, 2014 10:04 am  (#19) 
Offline
GimpChat Member

Joined: Sep 24, 2012
Posts: 275
Location: Scotland
Yup definitely seems good in all tests, looking forward to the release of this version because some new things are now possible :)


Top
 Post subject: Re: Inpainting without interpolation?
PostPosted: Sun Feb 23, 2014 3:30 am  (#20) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
I don't know whether the following comment makes sense to you, David:
Could it be possible in Impaint (patch based) having - beside the lookup size - a set of "lookup directions" (left, right, top, down; maybe with angles) each one selectable? Default seems to be: all, but sometimes it could be useful to exclude some direction, or include just one...
Maybe, this feature is already in and I don't see it.
Thanks

_________________
"Where am I ?"


Top
Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Center-Based Morphing/Interpolation

2

No new posts Lama Cleaner: a free, open-source inpainting tool

9



* Login  



Powered by phpBB3 © phpBB Group