GMIC warp command


I want to use warp command to do the color interpolation, but dont quite understand it. This is what the instruction said ‘[warping_field], _mode, _interpolation, _boundary_conditions, _nb_frames>0’. My question: 1, what does displacement field mean? 2. If I want only change the color interpolation, what should I do?


Have you read the documentation here:


Yes, but I don’t fully understand. For example,’’ -warp [displacement_field],_is_relative={ 0 | 1 },_interpolation,_boundary,_nb_frames>0" is listed on this page. However, what does displacement_field mean?


It is the shape of the warp. You need to generate one to apply on the image that you would like to warp. The square brackets indicate the need to reference that image in the buffer; e.g., [-1] would mean “select the last image in the buffer sequence”. To get the right interpolation, you just replace _interpolation with the desired numeric value. See step 6 for a breakdown of the command.

(G'MIC staff) #5

Maybe you should first try to explain why you want to use this command, so we could help.
Maybe it’s not the right command to use in your case ? A ‘displacement field’ is a quite common concept for a warping operator, for each pixel of the output image, it tells where to read the color from (in the source image).


I am not interested in changing the shape of the warp. What I want to just keep the same image, same shape and only change the color interpolation.


The reason I want to use warp is to try different color interpolation. For example, I have a raw image, then I want to see what the image would look like if I use nearest neighbor (0) or bilinear (1).


Hm… Other commands use interpolation as well. Is there a reason why you chose -warp?


The reason I choose -warp is because this is the ONLY command I know for color interpolation. If exists other command, what’s that?

(G'MIC staff) #10

Actually, all depend on what kind of data you want to interpolate. Data defined on a regular grid ? on a non-regular grid ? Your goal is not clear at that point because ‘interpolation’ can occur in a lot of different image processing operators.
Is it used to deform existing image data, to create new one ? etc…

For instance, if your goal is to create some smooth gradient image from a few colors, you need probably command -resize instead of -warp. Like this :

$ gmic 2,2,1,3 -rand 0,255 -resize 256,256,1,3,3

will create a smoothly varying colored image, where colors are linearly interpolated, like this one :



My goal is to convert a raw image (black and white) to a color (RGB) image through different color interpolation. I don’t know my data is regular grid or non-regular data, since they are the raw images captured from image sensors. Then I want to demosaic these images through 1. nearest neighbor 2, bilinear 3, cubic algorithms.

(G'MIC staff) #12

Ah that makes sense now.
This means you need implementations of different Bayer -> RGB algorithms to be able to compare.
In G’MIC, we don’t have much of that, only a (quite smart) command -bayer2rgb but this one uses Fourier transforms to estimate the RGB image.
The algorithm you are looking for is probably not hard to implement, but this is not done yet in G’MIC.


Got it. Even -warp has color interpolation parameter (0=nearest neighbor, 1=bilinear,2=cubic), I can’t use it for Bayer-RGB color interpolation. Right?

(G'MIC staff) #14

That’s it, command -warp is intended to deform locally an image by a warping field. This has almost nothing to do with Bayer to RGB reconstruction. Other commands (e.g. -resize) has options to choose the interpolation mode too, but each has a specific role, not related to bayer reconstruction.


OK. Thank you very much for your explanation. :slight_smile:

( #16

I have this drawing. I can distort it with this degrade?