Batch process images to apply levels adjustement to portion of each image

Hello, I’m new member and first post. Please forgive if this message is posted inappropriately.

I am brand new to G’MIC and came across it while searching for a solution to apply a ‘levels adjustment’ to a portion of an image in Gimp. The challenge is that I have a few hundred images I need to apply the exact same levels adjustment to.

Essentially I have a standard levels setting I want to apply to the top 20% of 100s of images.

I have looked at BIMP and although it allows me to apply an adjustment across multiple images, I can’t see any way to define only a portion of the image to apply the effect on. I believe I need to somehow select a portion of the image, then apply the adjustment/filter. I see no way to do this in Gimp.

I’m wondering if this can be accomplished using G’MIC. Appreciate any advice anyone can offer. Thanks.

@Michael_H Welcome to the forum! I started with a similar problem. At the time, I used ImageMagick. These past few years, I discovered G’MIC CLI. Now, I am writing commands for it! :slight_smile:

Yes, G’MIC CLI (command line) is the way to go. I suggest you give it a try, although command line might be a little daunting if you aren’t familiar with non-GUI environments.

I have several questions for you. The more info you provide the more we can assist you. First, what OS, GIMP and G’MIC (plugin) versions are you using? And where did you get the latter two from? Second,

What do you mean by that? As in intensity? For what purpose? Are you a photographer, researcher, restoring old photos, or something else?

Thank you very much for the quick reply. I am working with 8mm film images. I’m currently using the Windows version of Gimp v2.10.12 on Windows 7. For G’MIC I’ve downloaded v2.9.0 however have not yet installed. I’m pretty comfortable at the command line and did start reading up on Gimp scripting last night. I’m sure I could pick it up however don’t have the time to spare and need to find a quick solution. I’m also pretty functional with Ubuntu linux and opted to use Windows because of some other software I’m using (see below).

Here are a couple images that I think gives a good idea of what I’m trying to do. I have 100s these images. Essentially I’m extracting individual 8mm frames of movie films from a scan image containing 28 frames. My original plan was to write a program to extract the frames and convert to a video file, however came across a program I found here wkurz telecine. Although the software works, I find I need to adjust the scanned images (film strips) to prevent it from throwing errors.

By opening multiple images in Gimp as layers, selecting the area on the first layer, applying the levels adjustment to each layer, then exporting the layers as discrete images, I have been able to use the wkurz software to extract the frames and convert to a mpeg video. I’ve done this through an entirely manual workflow in Gimp on 15 strips of film. It’s tedious however solves the problem I am experiencing with the wkurz program.

Sincerely appreciate any thoughts you might have on how to use Gimp/G’MIC to batch adjust the images… or any other image software for that matter.

As for where I got the products… I used links from the download page here https://gmic.eu/download.shtml

If you can, please share one such strip or a part of one so that I can show you how you can do everything in G’MIC CLI alone.


PS Here is a quick example.

1 I took your image and cropped a section of the strip from your first screenshot.

fs

2 Used the following G’MIC command.

gmic fs.jpg +crop 0,0,100%,35% adjust_colors[1] 0,25 image[0] [1] remove[1] split x,7 output fs.jpg

Let me break it down for you:

a fs.jpg A file name by itself inputs the file into the G’MIC image buffer. Since it is the first image, it will be assigned to [0].

b +crop The + makes a copy of the image. This image will be assigned to [1]. Crop is a command that takes parameters. In this case, x0,y0,x1,y2; in other words, I am only cropping the bottom and keeping 35% of the top. This is the area you want to increase the contrast.

c adjust_colors[1] The first parameter is brightness and the second is contrast. We only want to adjust [1].

d image[0] [1] This one is a little more abstract. Basically, you are modifying image[0] by placing image[1] on top of it.

e remove[1] After that step, you don’t need image[1] anymore, so you remove it.

f split x,7 Next you want to split the only image left into 7 parts horizontally (x). You need to start with a good crop of the filmstrip. Otherwise, the segments won’t be evenly distributed.

g output fs.jpg And finally output it. Notice the output file name is the same as the input’s. Typically, this would overwrite the original, but since you have multiple images in the buffer now because you split it into 7, the naming will become fs_000000.jpg all the way to fs_000006.jpg

h That is only for one slide. However, you can place that code into code like this to make it iterate over all your images.

gmic input_glob *.jpg repeat $! local[$>] ...what_you_want_to_repeat... endlocal done

Read the documentation for more insight:
https://gmic.eu/reference.shtml

fs_000000 fs_000001 fs_000002 fs_000003 fs_000004 fs_000005 fs_000006

2 Likes

Wow! This is spectacular. Your steps a through d combined with step h looks like it will do everything I need.

While I appreciate the effort to slice the file into individual frames, I don’t think this will work for me. The reason is that although the film strips are all the exact same dimensions, the registration (left/right) of the strip shifts slightly from one strip to the next. It’s therefore necessary to determine where the first full sprocket hole is (reading from right to left), then calculate (based on 8mm film specification) where the first image frame starts. In any event, your example really opened my eyes to the capabilities of G’MIC. Your idea of taking two copies, adjusting the second and then applying the second to the first is pure genius.

Thanks also for the link to the reference page at gmic.eu as I had missed seeing it. Reading up on ‘crop’ it looks like it can accept both numeric and percentile values. Gimp reports my images to be 20869 × 2295 pixels. The coordinates of the rectangle section I want to adjust are (0,0,2089,800). Therefore I think replacing your values in the command to ‘+crop 0,0,100%,800’ would give me very precise control of the height of the section I want to adjust.

While I have your attention, do you know if it’s possible with G’MIC (perhaps as part of a larger script) to evaluate the pixel colors at a specific coordinate and then using if/then type logic cause something to occur (eg, if color at coordinates 0,0,10,10 is white then enlarge width of entire image by 20 pixels)?

Lastly what is your affiliation with G’MIC? Your responsiveness and quality of answer is a rarity I haven’t experienced since the very early days of the internet. Thank you!

@afre is quality, these answers are his normal thing, its pretty great!

1 Like

I just like helping people. :stuck_out_tongue: There is no greater satisfaction than loving and taking care of others. :dove:

It was a rough cut. Didn’t do it with a scalpel.

Definitely, though I would like someone else take the spotlight. Even consider tackling the challenge yourself. :wink:

Thank you very much for the help and sincerely appreciate the time and knowledge you shared. Your post saved me hours of time determining whether G’MIC was worth pursuing let alone figuring out the command line needed.

I’ll definitely read up on the various G’MIC commands and look into scripting as I actually prefer command line and code to GUIs. Maybe I’m old school… or maybe just old!

Cheers!

Learn by doing. Revealing the solution is no fun. :roll_eyes::rofl: