The recent version 7 of IM gives strange results when doing order dithering. The Posterized Ordered Dither Expansion example: magick convert gradient.png -ordered-dither o8x8,6 od_o8x8_6.gif yields just 2bpp bitmap.
Input:
Preffered output:
Actual output:
Is this an error or there is some syntax change?
It seems that the OrderedPosterizeImage feature hasn't yet been ported from IM6 to IM7. IM7 falls back on the original bi-level OrderedDitherImage method, ignoring the ",6" part of the specification.
I've posted a feature request on the ImageMagick discourse server.
Related
I am working on a project where my task is to identify machine part by its part number written on label attached to it or engraved on its surface. One such example of label and engraved part is shown in below figures.
My task is to recognise 9 or 10 alphanumerical number (03C 997 032 D in 1st image and 357 955 531 in 2nd image). This seems to be easy task however I am facing problem in distinguishing between useful information in the image and rest of the part i.e. there are many other numbers and characters in both image and I want to focus on only mentioned numbers. I tried many things but no success as of now. Does anyone know the image pre processing methods or any ML/DL model which I should apply to get desired result?
Thanks in advance!
JD
You can use OCR to the get all characters from the image and then use regular expressions to extract the desired patterns.
You can use OCR method, like Tesseract.
Maybe, you want to clean the images before running the text-recognition system, by performing some filtering to remove noise / remove extra information, such as:
Convert to gray scale (colors are not relevant, aren't them?)
Crop to region of interest
Canny Filter
A good start can be one of this tutorial:
OpenCV OCR with Tesseract (Python API)
Recognizing text/number with OpenCV (C++ API)
I'm trying to batch scale a load of xpm images to double pixel size. I can do this using ImageMagick like this:
convert infile.xpm -sample 200% outfile.xpm
However, the symbolic colour names are lost.
In the original input, the colour entries are as follows:
". c #007EBF s active_hilight_1",
"+ c #0A5E89 s active_color_1",
"# c #143D52 s active_shadow_1",
In the up-scaled version:
" c #143D52",
". c #0A5E89",
"X c #007EBF",
The colour names changed, which is fine, but as you can see the s <symbolic-name> suffixes are stripped.
Does anyone know a quick way to do this using ImageMagick or a similar (open-source) utility?
Thanks
EDIT: Seems ImageMagick can't due this due to a bug, but does anyone know any other tool which may be able to do this?
mogrify -sample 200% *.xpm
^ This works as long as you have a new (post 2019-09-02) version of ImageMagick with the xpm output bug fixed, as described here:
https://github.com/ImageMagick/ImageMagick/issues/1684
Today's master branch, for example, passes symbolic colour names through properly.
I need to pre-process an image to convert it to a high contrast dark-on-light background that is ideal to feed to OCR tools.
The pre-processing, which for starters I did in Gimp, simply involves running its Color->Invert operation, which gives me a result that works very well when fed into OCR tools.
This question though is how to replicate the same operation via OpenCV.
The following is the OpenCV code (via the Go wrapper for OpenCV) that I have managed so far:
func preprocessImage(inputImage gocv.Mat) {
white := gocv.NewMatWithSizeFromScalar(
gocv.Scalar{255.0, 255.0, 255.0, 255.0},
inputImage.Rows(), inputImage.Cols(),
inputImage.Type()
)
targetMat := gocv.NewMat()
gocv.Subtract(white, inputImage, &targetMat)
pngCompressionOptions := []int{gocv.IMWritePngCompression, 0}
gocv.IMWrite("result.png", targetMat, pngCompressionOptions)
}
However, this does not seem to match the results I obtain from Gimp.
As a sample, here's the original image:
Here's the result of applying Color->Invert via Gimp:
Here's the result I get via the OpenCV code shown above:
As is evident, there seems to quite some difference between the two results.
Gimp's documentation on what exactly Color->Invert does is a bit cryptic, at least to me. It mentions that "hues are replaced by their complementary colors" but am unclear as to how to replicate that.
Just to be clear, I am not expecting working Golang code in the answers. I am just looking for some hints as to what OpenCV functions I should string together (in any language, I can port that to Go) in order to replicate Gimp's Color-Invert operation.
I am unfamiliar with Go, but it looks like your image got converted to greyscale on opening.
Check your flags/parameters where you loaded it and that you have at least three, rather than one single channel.
I'm trying to convert a tangent space normal map to a height/displacement map. For sure this will be not 100% accurate speaking in terms of "exact height" for each pixel. But the relative height from each pixel to the next is more than enough.
Available Algorithm + Info's:
http://www.cournia.com/devnull/n2h/n2h.pdf
Questions:
1. How to convert a normal-to-height map in Photoshop/Gimp? Is there a way using these tools? Beside; I don't wan't to use CrazyBump or any other Texture-Tools. This has to run via CL later on. A Photoshop solution is more or less just a pre-step to understand workflow a bit better.
If not possible with PS/Gimp; how to include the algorithm in an imagemagick process?
I've checked already Doom3:-Normal2Height; Crazybump & all other texture tools like Nvidia's PS-Plugin, xNormal, Awesomebump, SSBump, etc. I'd need this function working with Imagemagick.
Any help is very much welcome. Python preferable.
thx
There are a couple of possibilities for doing that with ImageMagick.
Firstly, you could implement your own process module. When running configure to install ImageMagick, you would then do:
./configure --with-modules=yes
Then, when you want to apply your bumpmap processing on the command-line, you would do:
convert input.png -process analyse <param1> <param2> result.png
Your processing needs to be written in C/C++ and the best description I know of is on Alan Gibson's webpages here.
Secondly, you could write your entire processing using Magick++ which is the C++ binding to ImageMagick. Best description I know of is here with sample code here.
I am doing image manipulation on the png images. I have the following problem. After saving an image with imwrite() function, the size of the image is increased. For example previously image is 847KB, after saving it becomes 1.20 MB. Here is a code. I just read an image and then save it, but the size is increased. I tried to set compression params but it doesn't help.
Mat image;
image = imread("5.png", -1);
vector<int> compression_params;
compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION);
compression_params.push_back(9);
compression_params.push_back(0);
imwrite("output.png",image,compression_params);
What could be a problem? Any help please.
Thanks.
PNG has several options that influence the compression: deflate compression level (0-9), deflate strategy (HUFFMAN/FILTERED), and the choice (or strategy for dynamically chosing) for the internal prediction error filter (AVERAGE, PAETH...).
It seems OpenCV only lets you change the first one, and it hasn't a good default value for the second. So, it seems you must live with that.
Update: looking into the sources, it seems that compression strategy setting has been added (after complaints), but it isn't documented. I wonder if that source is released. Try to set the option CV_IMWRITE_PNG_STRATEGY with Z_FILTERED and see what happens
See the linked source code for more details about the params.
#Karmar, It's been many years since your last edit.
I had similar confuse to yours in June, 2021. And I found out sth which might benefit others like us.
PNG files seem to have this thing called mode. Here, let's focus only on three modes: RGB, P and L.
To quickly check an image's mode, you can use Python:
from PIL import Image
print(Image.open("5.png").mode)
Basically, when using P and L you are attributing 8 bits/pixel while RGB uses 3*8 bits/pixel.
For more detailed explanation, one can refer to this fine stackoverflow post: What is the difference between images in 'P' and 'L' mode in PIL?
Now, when we use OpenCV to open a PNG file, what we get will be an array of three channels, regardless which mode that
file was saved into. Three channels with data type uint8, that means when we imwrite this array into a file, no matter
how hard you compress it, it will be hard to beat the original file if it was saved in P or L mode.
I guess #Karmar might have already had this question solved. For future readers, check the mode of your own 5.png.