What you want is referred to as "threshold" in image processing. Basically, it takes an image as an input and outputs an image that has all pixels with a value below a given threshold set to black, and all pixels the value of which is above the threshold set to white. This results in a black-and-white image from an arbitrary input image.
Generally, you want to convert to grayscale first for more predictable results, but it is possible to threshold a full-color image as well.
You can use a graphical tool such as GIMP to do this interactively (you'll find the tool through the main menu -> Colors -> Threshold), or you can use ImageMagick something like this:
convert colored.png -threshold 75% thres_colored.png
Running the above command on the example image produces the result shown below.
Since thresholding is often somewhat of a trial-and-error process to get a result you're happy with, particularly if the source image is not very close to black-and-white already, I recommend the GUI approach if possible, but if that is not an option for whatever reason you can do it through the command line as well. For finer control of the output, you can use tools like color curves, levels and contrast first to isolate the light and dark portions of the image better before thresholding. (Actually, threshold can be seen as an extreme case of using the color curves tool.)
Since you are new to the command line I will go over the steps one by one, explaining each along the way.
When you open up a terminal/shell/command-line, you'll see a command-prompt like so:
username:~ $
or something similar. You'll almost certainly start out in your home directory, which has the name of your username.
Let's say your two image folders are folder1
and folder2
. You said they are on the Desktop, so first we change to the Desktop
directory:
cd Desktop
The cd
command is the "change directory" command, doing exactly what it sounds like.
Now, we are going to use the mv
command, which of course stands for "move".
mv -i folder1/* folder2/
I used the -i
flag, which stands for "interactive", which causes a prompt to appear every time there is a file-name conflict. You'll be asked whether you want to overwrite the destination file or not.
After this, you'll have to manually resolve any conflicts* by renaming the files left in folder1
so they don't conflict with the files in folder2
. Finally, run the above command again, but this time you should get no conflicts.
After all this, your folder1
directory should be empty, so go ahead and remove it with
rmdir folder1
and you're done!
I really recommend you go through a simple bash tutorial like this one to learn the basics.
- Note that it is of course possible to resolve naming conflicts programmatically by renaming each of the files in
folder1
, but I tried to keep things simple.
Best Answer
To use
identify
from ImageMagic with sorting, let's change the output format to make that easier:We want to sort on width or height, so they should be easy to address as sort key field. To output width and height as the first two columns, and then the filename, we use
"%w %h %f\n"
.The resulting list of lines of the form
w h somefile.png
are then sorted numerically (-n
) on either the first column, the width, or second column, the height.We sort reverse (
-r
) so the larges value appears first:Sorting by width in the first column:
Sorting by height, which is in the second column:
The part of the line after the second space is only the file name, so we do not need to escape it; Just cutting off the two columns gives a clean filename, (as long as the names do not contain newlines).
If you are not interested in the whole list, but only a few of the larges files, use
head
on the result:When we show only the largest file, or files, maybe we do not really care about the size anymore, but need the clean filenames: