3
votes

I downloaded ImageMagick so I could batch process folders of images at work, cropping them to size and then slicing them into 12 equal pieces. I can do each task individually, but I'd rather execute it all in one line using STDIN and STDOUT. However, even after looking through answers here and the documentation on the website, I'm not any closer to making it work.

I'm working in Windows Powershell. Here's what I've tried, working with a single image:

convert -crop '5072x3552+87+0' image.jpg jpg:- | convert -crop '1268x1184' - jpg: - | convert -crop '1268x1030+0+0' - C:\folder1\folder2\folder3\square.jpg

This gives me a series of errors:

convert.exe: no decode delegate for this image format `' @ error/constitute.c/ReadImage/508.

convert.exe: no images defined `jpg:-' @ error/convert.c/ConvertImageCommand/3253.

convert.exe: no decode delegate for this image format `' @ error/constitute.c/ReadImage/508.

convert.exe: no images defined `C:\users\lmcane\desktop\imagem\test\leaf.jpg' @ error/convert.c/ConvertImageCommand/3253

I'm using ImageMagick 7.0.2 on Windows 7. Windows PowerShell is opened as administrator.

Additional guidance on formatting STDIN and STDOUT in imagemagick would be welcome.

Any help appreciated.

image for reference

process for single original image

2
I think you are making this harder than necessary. I understand you have a folder full of images and that's fine but I don't see what you are trying to do to each image. Can you explain that in simple English please? You want to crop it to what size? Starting where? And then split it into 12 equal portions - is that 12 equal slices the full width of the inage? Or 12 slices each the full height? Or 3x4? Or 4x3? Or 6x2? What are the slices to be called?Mark Setchell
I have a scanned image with a 3x4 grid on it and some excess on the left and bottom. Goal: extract each piece of the grid. Step 1) remove excess from left and bottom with crop. Step 2) Use imagemagick's tile crop function to chop the image into 12 pieces. Step 3) some purposes require that the bottom part of each resulting image be removed. This is accomplished through further cropping, resulting in a clean image of the object in the grid. The pixel heights/widths in each step are calculated so that no excess is left to clean out of the destination folder.MahiMai
Can you post an image?Mark Setchell
I edited my original post with an image. Hopefully it'll make more sense to you now.MahiMai

2 Answers

0
votes

I would try doing the first trim of the edges using -fuzz (to allow for small differences in the border colour) and -trim. That gets you this:

convert grid.png -fuzz 30% -trim trimmed.png

Then, I would tile to 4x3 and repage the images so they forget their positions in the original image:

convert trimmed.png -crop 4x3@ +repage step2.png

Now crop off the tops, bottoms and sides and save the individual 12 frames:

convert step2.png -crop 130x100+20+20 f-%02d.png

Now you can trim the excess, using a slightly different fuzz as there seems to be less variation here than in the outer edge of the original image. And, I have also put all the commands together in one that does all the steps for all 12 images in one go:

convert grid.png -fuzz 30% -trim -crop 4x3@ +repage -crop 130x100+20+20 -fuzz 5% -trim f-%02d.png

You may have to play with the fuzz factor for other images, but you should see how it works now.

0
votes

I can't explain why convert throws these errors, but I was able to get it to work by using xwd as the transport format:

convert -crop '5072x3552+87+0' image.jpg xwd:- |
    convert -crop '1268x1184' xwd:- xwd:- |
    convert -crop '1268x1030+0+0' xwd:- C:\folder1\folder2\folder3\square.jpg