Drawing a 20x20 pixel greyscale image - image

I'm currently trying to write a program that takes a user-inputted 20x20 pixel greyscale image of a digit and predicts what number the user drew. Here is a sample image of what a typical user input would be:
How can I ask the user to draw such an image?

Maybe shell out to ImageMagick to create a 400x400 greyscale image:
convert -size 400x400 xc:gray image.bmp
and then start MS Paint (Windows) or GIMP (Linux/macOS) to edit the image. Then, when the user exits, resize the image to 20x20 and save as a PGM which is dead easy to read and necessarily greyscale:
convert image.bmp -resize 20x20 result.pgm

Related

There have any process to detect an image is a black&white image or a colored image?

I need to detect an image is a color image or black&white image. But don't understand what will be the process or there have any function to detect it. If there have no function to detect it then what will be the process?
Image file has mode, which tells if it is RGB, grayscale or B&W.
I assume you know that and you are trying to examine a RGB image to see if it only has black / white color. In this case you can calculate the histogram of the image in all R/G/B channels, the black and white will have two sharp peaks in all three channels.
Please use a image editing software like GIMP and experiment.

Grayscale, monochrome, binary image in matlab

In Matlab,
An 8-bit gray scale image has pixel values ranging from 0 to 255. The pixel depth may vary (16-bit, 32-bit, etc)
A binary image has pixel values, either 0 or 1 (logical)
My question is that, is monochrome image, a binary image or a gray scale image as per points 1 and 2. I need clarification because I want to be 100 % sure about monochrome image.
(As per 'Digital Image Processing Using Matlab' by Gonzalez, Woods, Eddins, a monochrome image is a grayscale image. (Topic 3.2, pg no. 66))
Monochrome and grayscale are mostly interchangeable. Monochrome data has only one color, but it's not always gray. For example digital x-ray data is monochrome because it has only intensity. The printout is typically grayscale but you could also use any other color.
Sepia images are also monochrome, but strictly speaking not grayscale.

Image resizing, maintaing image size - beginner question

Im attempting to resize an image from 480x800 to 320x240. Below are the results. The original image has an oval shaped circle whereas the resized image has a more spherical shape. Is it possible to resize the original image so that the circle and rectangle are in their original proportions but smaller?
Can imagemagick or gimp (or other software) achieve this ?
Here's Imagemagick solution.
1) If you want large image to just fit 320x240 box and leave proportions, use:
convert test.png -size 320x240 resized.png
That will produce image sized 144x240.
http://www.imagemagick.org/Usage/resize/#resize
2) If you want large image to completely fill a specific image size, use:
convert test.png -resize 320x240\> \
-size 320x240 xc:blue +swap -gravity center -composite \
resized.jpg
That will produce image sized 320x240 with resized big image in center and blue fill on sides.
http://www.imagemagick.org/Usage/resize/#space_fill

crop gif image using libMagick

i am trying to crop a gif image using the libMagick.so library.
./convert --version
Version: ImageMagick 6.2.8 03/31/08 Q16 file:/usr/share/ImageMagick-6.2.8/doc/index.html
using the following command:
convert img.gif -crop 91x68+6+116 out.gif
the out.gif image gets crop, but not re sized. i get the same image size while all of it is transparent except the 91 pixels starting at 6 pixels from the left point and 68 pixels starting 116 pixels from the top.
how can i make the convert command crop and leave only the cropped part as the output image.
by the way, when my output image is jpg, i get the expected results.
You need to add the -repage option for GIF files:
convert img.gif -crop 91x68+6+116 -repage 0x0 out.gif
The problem is that GIFs can contain multiple images (of different sizes) when they're animated so cropping just affects one of the images while leaving the overall GIF canvas size untouched. Using 0x0 for the canvas size is an easy shortcut to make ImageMagick figure out how big the image should be:
A given a canvas size of zero such as '0x0' forces it to recalculate the canvas size so the image (at its current offset) will appear completely on that canvas.

How to Convert Gray scaled image to RGB image?

I am on MAC OSX.
How to convert an gray scaled image to the RGB format.
Can i use the CIFilters for converting? Or any other way
And also i want to reverse the operation. i.e., convert the RGB format to Gray scaled format.
Regards,
Dhanaraj.
You can draw the grayscale image into an RGB-color context and export that image. Of course, the ability to draw a grayscale image into a non-grayscale context means you probably don't need to convert the image in the first place, since it will be done for you on-the-fly.
Core Image requires RGB images as input and produces them as output. I think it will convert a non-RGB image for you, so you could just use some simple filter in its identity configuration, but that's unnecessary.
What are you really trying to do that requires you to convert the image?

Resources