Open-source News

KDE Prepares Smarter KRunner, Steam Scaling Better Under Plasma Wayland

Phoronix - Sat, 11/05/2022 - 17:19
It's Saturday morning and that means there is a new weekly blog post by KDE developer Nate Graham about the prominent desktop changes that occurred this week...

Fix scanned images with ImageMagick

opensource.com - Sat, 11/05/2022 - 15:00
Fix scanned images with ImageMagick Seth Kenlon Sat, 11/05/2022 - 03:00

Years ago while rummaging through the contents of a shelf in a used bookstore, I happened upon a booklet titled "UNIX System Command Summary for Berkeley 4.2 & 4.3 BSD," published by Specialized Systems Consultants. I bought it as a curiosity item because it was nearly 20 years old yet still largely applicable to modern Linux and BSD.

That amused me then and now. A booklet written in 1986 was still largely relevant in 2016, while books on the same shelf about a proprietary OS weren't worth the paper they were printed on. (Think about it: What technology do you think is going to survive a zombie apocalypse?) I've had the booklet on my own bookshelf for several years now, but it occurred to me that it's probably worth doing a little digital preservation of this artifact, so I decided to scan the booklet to create a CBZ ebook.

Scanning was easy, albeit time-consuming, with Skanlite. After I was finished, however, I discovered that some pages weren't quite level.

Image by:

(Seth Kenlon, CC BY-SA 4.0)

In printing, this is called a registration problem, meaning that the position of what's being printed isn't correctly orientated on the page.

More open source alternatives Open source project management tools Trello alternatives Linux video editors Open source alternatives to Photoshop List of open source alternatives Latest articles about open source alternatives ImageMagick

ImageMagick is a non-interactive terminal-based graphics editor. It might seem counterintuitive to try to edit a graphic in a graphic-less environment like a text-only terminal, but it's actually very common. For instance, when you upload an image to use as a profile picture to a web application, it's likely that a script on the application's server processes your image using ImageMagick or its libraries. The advantage of a non-interactive editor is that you can formulate what needs to be done to a sample image, then apply those effects to hundreds of other images at the press of a button.

ImageMagick is generally just as capable as any graphics editor, as long as you take the time to uncover its many functions and how to combine them to achieve the desired effects. In this case, I want to rotate pages that are askew. After searching through ImageMagick's documentation, I discovered that the ImageMagick term for the solution I needed was called deskew. Aligning your terminology with somebody else's terminology is a challenge in anything that you don't already know, so when you approach ImageMagick (or anything), keep in mind that the word you've decided describes a problem or solution may not be the same word used by someone else.

To deskew an image with crooked text using ImageMagick:

$ convert page_0052.webp -deskew 25% fix_0052.webp

The -deskew option represents the threshold of acceptable skew. A skew is determined by tracing peaks and valleys of objects that appear to be letters. Depending on how crooked your scan is, you may need more or less than 25% threshold. I've gone as high as 80%, and so far nothing under 25% has had an effect.

Here's the result:

Image by:

(Seth Kenlon, CC BY-SA 4.0)

Fixed! Applying this to the remaining 55 pages of the document fixed skewed pages while doing nothing to pages that were already straight. In other words, it was safe to run this command on pages that needed no adjustment, thanks to my threshold setting.

Cropping an image with ImageMagick

After correcting for a skew, and because I scanned more of each page than necessary anyway to prevent accidentally cutting off words, I decided that it made sense to crop my corrected pages. I was happy to keep some space around the margins, but not quite as much as I had. I use the crop function of ImageMagick often enough for images on this very website, so I was familiar with the option. However, I needed to determine how to crop each page.

First, I needed the size of the image:

$ identify fixed_0052.webp
WEBP 1128x2593 1128x2593+0+0 8-bit sRGB 114732B 0.020u 0:00.021

Knowing the size, I was able to make some estimations about how many pixels I could stand to lose. After a few trial runs, I came up with this:

convert fix_0052.webp -gravity Center -crop 950x2450+0+0 crop_0052.webp

This isn't an exact fit, but it proved important when I applied it to other images in the booklet. The pages varied in content and scanner placement here and there, so I was happy to give each one a little breathing room.

Here's the corrected and cropped image:

Image by:

(Seth Kenlon, CC BY-SA 4.0)

Batch image editing with open source

The beauty of ImageMagick is that once you've figured out the formula for fixing your image, you can apply that fix to all images requiring the same fix. I do this with GNU Parallel, which uses all my CPU cores to finish image correction across hundreds of pages. It doesn't take long, and the results speak for themselves. More importantly, I've got a digital archive of a fun artifact of UNIX history.

It's easy to correct images, even in batches, with this open source tool.

Image by:

Ray Smith

Tools Art and design What to read next This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License. 5014 points Minnesota

Jim Hall is an open source software advocate and developer, best known for usability testing in GNOME and as the founder + project coordinator of FreeDOS. At work, Jim is CEO of Hallmentum, an IT executive consulting company that provides hands-on IT Leadership training, workshops, and coaching.

| Follow jimfhall | Connect jimfhall User Attributes Correspondent Open Sourcerer People's Choice Award People's Choice Award 2018 Author Correspondent Contributor Club Register or Login to post a comment.

AMD Posts Linux Patches For "Automatic IBRS" Feature New To Zen 4

Phoronix - Sat, 11/05/2022 - 06:34
A Friday patch series reveals a new security feature with Zen 4 previously not documented: Automatic IBRS...

Intel MIC Offloading For Xeon Phi Dropped With GCC 13 Compiler

Phoronix - Sat, 11/05/2022 - 00:50
On the same day as new GCC compiler patches for next-generation processors coming out for those wares that are more than one year out, the GNU Compiler Collection dropped a remnant from Intel's past: the Many Integrated Core "MIC" architecture support with Xeon Phi for offloading...

Linux Patch Pending To Help Lower Alder Lake N & Raptor Lake P Power Consumption

Phoronix - Fri, 11/04/2022 - 21:00
A patch on its way to the mainline Linux kernel tunes Alder Lake N and Raptor Lake P mobile processors to have slightly lower power consumption out-of-the-box to help with battery life and thermal characteristics...

Pages