large becomes small and small becomes large
Created: 22 July 2000
Updated: 27 October 2011
Author: Fred Weinhaus, with editing and formatting by Anthony Thyssen, Anthony.Thyssen@gmail.com
Examples Generated with: fft hough 文字图像预处理一条龙操作imagemagick can 'makefile' be used as batch file? in place of 'for' - 图1
URL: https://legacy.imagemagick.org/Usage/fourier/
信号和系统 级数
https://legacy.imagemagick.org/Usage/transform/

can
makefile …… batch file
.jpg:
rgb2gray:for /f %i in (‘dir
.jpg /b’) do ffmpeg -i %i -vf hue=s=0,eq=contrast=1 %~ni_gray.jpg
//maybe once more
edge detect: for /f %i in (‘dir _gray.jpg /b’) do convert %i -edge 3 -negate %~ni_edge.jpg
how to enhance those strokes which is too thin 要用gaussfilter L=A/B分布去除光照
……(就是说咱们还有去光照滤镜没有实现e)
对已去光照的扫描仪图片的边缘加强可以试用edge
hough transform will get all lines possible and slower than canny or edge
for /f %i in (‘dir
_gray.jpg /b’) do convert %i -negate -hough-lines 5x5+20 %~ni_hough.jpg

The Fourier Transform

An image normally consists of an array of ‘pixels’ each of which are defined by a set of values: red, green, blue and sometimes transparency as well. But for our purposes here we will ignore transparency. Thus each of the red, green and blue ‘channels’ contain a set of ‘intensity’ or ‘grayscale’ values.This is known as a raster image ‘in the spatial domain‘. This is just a fancy way of saying, the image is defined by the ‘intensity values’ it has at each ‘location’ or ‘position in space’.But an image can also be represented in another way, known as the image’s ‘frequency domain‘. In this domain, each image channel is represented in terms of sinusoidal waves.In such a ‘frequency domain‘, each channel has ‘amplitude’ values that are stored in locations based not on X,Y ‘spatial’ coordinates, but on X,Y ‘frequencies’. Since this is a digital representation, the frequencies are multiples of a ‘smallest’ or unit frequency and the pixel coordinates represent the indices or integer multiples of this unit frequency.This follows from the principal that “any well-behaved function can be represented by a superposition (combination or sum) of sinusoidal waves”. In other words, the ‘frequency domain’ representation is just another way to store and reproduce the ‘spatial domain’ image.But how can an image be represented as a ‘wave’?

Images are Waves

Well if we take a single row or column of pixel from any image, and graph it (generated using “gnuplot” using the script “im_profile“), you will find that it looks rather like a wave.
fft hough 文字图像预处理一条龙操作imagemagick can 'makefile' be used as batch file? in place of 'for' - 图2 fft hough 文字图像预处理一条龙操作imagemagick can 'makefile' be used as batch file? in place of 'for' - 图3 fft hough 文字图像预处理一条龙操作imagemagick can 'makefile' be used as batch file? in place of 'for' - 图4

convert holocaust_tn.gif -colorspace gray miff:- | im_profile -s - image_profile.gif

If the fluctuations were more regular in spacing and amplitude, you would get something more like a wave pattern, such as…
fft hough 文字图像预处理一条龙操作imagemagick can 'makefile' be used as batch file? in place of 'for' - 图5 fft hough 文字图像预处理一条龙操作imagemagick can 'makefile' be used as batch file? in place of 'for' - 图6 fft hough 文字图像预处理一条龙操作imagemagick can 'makefile' be used as batch file? in place of 'for' - 图7

convert -size 20x150 gradient: -rotate 90 -function sinusoid 3.5,0,.4 wave.gif im_profile -s wave.gif wave_profile.gif

However while this regular wave pattern is vaguely similar to the image profile shown above, it is too regular.However if you were to add more waves together you can make a pattern that is even closer to the one from the image.
fft hough 文字图像预处理一条龙操作imagemagick can 'makefile' be used as batch file? in place of 'for' - 图8 fft hough 文字图像预处理一条龙操作imagemagick can 'makefile' be used as batch file? in place of 'for' - 图9 fft hough 文字图像预处理一条龙操作imagemagick can 'makefile' be used as batch file? in place of 'for' - 图10 fft hough 文字图像预处理一条龙操作imagemagick can 'makefile' be used as batch file? in place of 'for' - 图11 fft hough 文字图像预处理一条龙操作imagemagick can 'makefile' be used as batch file? in place of 'for' - 图12 fft hough 文字图像预处理一条龙操作imagemagick can 'makefile' be used as batch file? in place of 'for' - 图13 fft hough 文字图像预处理一条龙操作imagemagick can 'makefile' be used as batch file? in place of 'for' - 图14

convert -size 1x150 gradient: -rotate 90 \
-function sinusoid 3.5,0,.25,.25 wave_1.png convert -size 1x150 gradient: -rotate 90 \
-function sinusoid 1.5,-90,.13,.15 wave_2.png convert -size 1x150 gradient: -rotate 90 \
-function sinusoid 0.6,-90,.07,.1 wave_3.png convert wave_1.png wave_2.png wave_3.png \ -evaluate-sequence add added_waves.png

See also Adding Biased Gradients for an alternative example to the above.This ‘wave superposition‘ (addition of waves) is much closer, but still does not exactly match the image pattern. However, you can continue in this manner, adding more waves and adjusting them, so the resulting composite wave gets closer and closer to the actual profile of the original image. Eventually by adding enough waves you can exactly reproduce the original profile of the image.This was the discovery made by the mathematician Joseph Fourier. A modern interpretation of which states that “any well-behaved function can be represented by a superposition of sinusoidal waves”.In other words by adding together a sufficient number of sine waves of just the right frequency and amplitude, you can reproduce any fluctuating pattern. Therefore, the ‘frequency domain’ representation is just another way to store and reproduce the ‘spatial domain’ image.The ‘Fourier Transform‘ is then the process of working out what ‘waves’ comprise an image, just as was done in the above example.

2 Dimensional Waves in Images

The above shows one example of how you can approximate the profile of a single row of an image with multiple sine waves. However images are 2 dimensional, and as such the waves used to represent an image in the ‘frequency domain’ also needs to be two dimensional.Here is an example of one such 2 dimensional wave.The wave has a number of components to it.Image example
so as in 3d, 4d
will the world initially consist of fourier waves, i.e. string is wave
https://mp.weixin.qq.com/s/1ho7r9XlBwdqISBGWzQ9RQ


Using FFT/IFT In ImageMagick

Implementation Notes

ImageMagick makes use of the FFTW, Discrete Fourier Transform Library which requires images to be converted to and from floating point values (complex numbers), and was first implemented in IM version 6.5.4-3.To make it work as people generally expect for images, any non-square image or one with an odd dimension will be padded (using Virtual Pixels to be square of the maximum width or height of the image. To allow for proper centering of the ‘FFT origin’ in the center of the image, it is also forced to have an even (multiple of 2) dimensions. The consequence of this is that after applying the Inverse Fourier Transform, the image will need to be cropped back to its original dimensions to remove the padding.As the Fourier Transform is composed of “Complex Numbers“, the result of the transform cannot be visualized directly. Therefore, the complex transform is separated into two component images in one of two forms.

fft hough 文字图像预处理一条龙操作imagemagick can 'makefile' be used as batch file? in place of 'for' - 图15
Complex Number
Real/Imaginary

Real and Imaginary

The normal mathematical and numerical representation of the “Complex Numbers“, is a pair of floating point values consisting of ‘Real’ (a) and ‘Imaginary’ (b) components. Unfortunately these two numbers may contain negative values and thus do not form viewable images.As such this representation can not be using in a normal version of ImageMagick, which would clip such images (see example below of the resulting effects.However when using a HDRI version of ImageMagick you can still generate, use, and even save this representation of a Fourier Transformed image. They may not be useful or even viewable as images in their own right, but you can still apply many mathematical operations to them.To generate this representation we use the ‘plus’ form of the operators, “+fft“ and “+ift“, and will be looked at in detail below in FFT as Real-Imaginary Components.

fft hough 文字图像预处理一条龙操作imagemagick can 'makefile' be used as batch file? in place of 'for' - 图16
Complex Polar
Magnitude/Phase

Magnitude and Phase

Direct numerical representation of the “Complex Numbers“ is not very useful for image work. But by plotting the values onto a 2-dimensional plane, you can then convert the value into a Polar Representation consisting of ‘Magnitude’ (r) and ‘Phase’ (θ) components.This form is very useful in image processing, especially the magnitude component, which essentially specifies all the frequencies that go to make up the image.The ‘Magnitude’ component only contains positive values, and is just directly mapped into image values. It has no fixed range of values, though except for the DC or zero frequency color, the values will generally be quite small. As a consequence of this the magnitude image generally will appear to be very dark (practically black).By scaling the magnitude and applying a log transform of its intensity values usually will be needed to bring out any visual detail. The resulting ‘log-transformed’ magnitude image is known as the image’s ‘spectrum’. However remember that it is the ‘magnitude’ image, and not the ‘spectrum’ image, that should be used for the inverse transform.The DC (Short for “Direct Current”) or “Zero Frequency”, color that appears at the central ‘origin’ of the image, will be the average color value for the whole image. Also as input images not contain ‘imaginary’ components, the DC phase value will also always have zero phase, producing a pure-gray color.The ‘Phase’ component however ranges from -π to +π. This is first biased into a 0 to 2π range, then scaled into actual image values ranging from 0 to QuantumRange (as determined by the Compile Time Memory Quality). As a consequence of this, a zero phase will have a pure-gray value (as appropriate for each channel), while a negated phase will be a pure-black (‘0’) value. Note that a pure-white (‘QuantumRange‘) is almost but not quite the same thing.A Magnitude and Phase FFT representation of an image is generated using the normal FFT operators, “+fft“ and “+ift“. This will be looked at first in Generating FFT Images and its Inverse.

ImageMagicK的convert参数draw笔记

2011年8月26日admin发表评论阅读评论
convert通过draw可以在已有的图片上绘制一些文字、线条、形状等。可能会用text、line、rectangle、roundRectangle、circle、ellipse等,下面逐一来说明。

  • text,把一段文本绘制到已有图片上。基本命令格式:convert 图片 -draw “text x坐标,y坐标 ‘文本信息’” ?结果图片,另外还可有一些参数是可以设置的,比如字体,字体大小,字体颜色已经重新定义坐标原点。

convert -size 512x50 xc:gray -gravity southeast -fill red -pointsize 24 -draw “text 20,5 ‘hello netingcn.com!’” txt.png
上述命令中使用gravity来重新定义坐标,关于gravity的更多信息,请参考ImageMagicK之gravity参数详解,-fill 设置文字的颜色,颜色能够使用类似#ff00ff的方式,但是需要用双引号引起来,-pointsize 24设置文字的大小, -draw 后面引号中第一个单词是text,表明是在图片上绘制一个设置的文本,20是x坐标,5则是y坐标,hello netingcn.com!是绘制到图片上的文本信息,如果文本信息中含有空格,需要用单引号引起来,没有空格也可以用单引号,所以建议总是使用单引号。不过遗憾的是不能把中文通过这种方式绘制到图片,要把中文加在图片是,需要另外的方法。结果如下图:
fft hough 文字图像预处理一条龙操作imagemagick can 'makefile' be used as batch file? in place of 'for' - 图17

  • line,在图片上绘制一条直线,基本命令格式:convert 图片 -draw “line 起点x坐标,起点y坐标 ?终点x坐标,终点y坐标” ?结果图片,可以使用的参数有-stroke 来指定线条的颜色,-strokewidth 指定线的宽度。

convert -size 512x50 xc:gray -stroke white -strokewidth 4 -draw “line 10,25 500,25” line.png
fft hough 文字图像预处理一条龙操作imagemagick can 'makefile' be used as batch file? in place of 'for' - 图18

  • rectangle、roundRectangle,两者功能都是在图片上绘制一个矩形,前者是直角,后者可以绘制圆角。

    convert -size 150x150 xc:gray -stroke red -strokewidth 2 -fill white -draw “Rectangle 10,10 140,140” rect-1.png convert -size 150x150 xc:gray -stroke red -strokewidth 2 -fill white -draw “roundRectangle 10,10 140,140 8,8” rect-2.png
    说明:参数-stroke 来指定边框的颜色,-strokewidth 指边框的宽度,-fill 矩形的填充颜色,可以用none设置为不填充任何颜色,如果没有-fill参数,默认填充为黑色,Rectangle 与roundRectangle 后第一组参数是确定矩形左上角的坐标,第二组是确定右下角的坐标,roundRectangle的第三组参数是确定圆角的幅度,如果是0,0话,就是直角,所以可以直接用roundRectangle 来代替Rectangle 。示例图片如下:
    fft hough 文字图像预处理一条龙操作imagemagick can 'makefile' be used as batch file? in place of 'for' - 图19 fft hough 文字图像预处理一条龙操作imagemagick can 'makefile' be used as batch file? in place of 'for' - 图20

  • circle、ellipse,分别绘制圆和椭圆。其实也可以用椭圆来完成圆的绘制。下面用例子说明:

    convert -size 140x140 xc:gray -stroke red -strokewidth 2 -fill white -draw “circle 70,70 5,70” circle.png convert -size 140x140 xc:gray -stroke red -strokewidth 2 -fill white -draw “ellipse 70,70 65,65 0,360” ellipse-1.png convert -size 140x140 xc:gray -stroke red -strokewidth 2 -fill white -draw “ellipse 70,70 60,30 0,360” ellipse-2.png convert -size 140x140 xc:gray -stroke red -strokewidth 2 -fill white -draw “ellipse 70,70 60,30 90,270” ellipse-3.png
    说明:同矩形一样,参数-stroke 来指定边框的颜色,-strokewidth 指边框的宽度,-fill 矩形的填充颜色,可以用none设置为不填充任何颜色。circle和ellipse中的第一组参数都是代表圆心的坐标,但是他们第二组参数含义不同,circle的第二组参数是圆的任何一边缘坐标,所以圆的半径就是两组坐标的距离,ellipse的第二组参数中的第一个是横向的最大长度、第二个是纵向最大高度,第三组参数是绘制的区间,区间是0~360度,0度是原点开始到从左到右,度数是顺时针方向。有了这个参数就可以很容易绘制半圆,1/4圆,乃至圆的任何一部分,所以ellipse比circle的功能更加强大。上述的第二条命令完成和第一条命令同样的事。示例图片如下:
    fft hough 文字图像预处理一条龙操作imagemagick can 'makefile' be used as batch file? in place of 'for' - 图21 fft hough 文字图像预处理一条龙操作imagemagick can 'makefile' be used as batch file? in place of 'for' - 图22 fft hough 文字图像预处理一条龙操作imagemagick can 'makefile' be used as batch file? in place of 'for' - 图23 fft hough 文字图像预处理一条龙操作imagemagick can 'makefile' be used as batch file? in place of 'for' - 图24
    欢迎转载,转载请注明文章出处,谢谢!https://www.netingcn.com/imagemagick-convert-draw.html