使用Mathematica进行图像处理

Max*_*rai 1 linux wolfram-mathematica

我在上一篇文章之后创建了这个主题.我无法运行以下代码(由@belisarius编写):

a = Image["path/file.png"]
b = Image@ArrayPad[ImageData@a, {{40, 0}, {40}, {0}}, {1, 1, 1}];
f[image_, angleMult_] := ImageForwardTransformation[image, (
    fi = ArcTan[Abs[#[[2]]/(#[[1]] - .5)]];
    fi1 = angleMult fi (#[[1]]^2 + #[[2]]^2)/2;
    {(1/2 - Sin[fi1] #[[2]] - Cos[fi1]/2 + 
       Cos[fi1] #[[1]]), -Sin[fi1]/2 + Sin[fi1] #[[1]] + 
      Cos[fi1] #[[2]]}) &]
t = Table[f[b, x], {x, 0, .2, .02}];
t1 = Reverse@t;
Export["anim.gif", Join[t, t1], "DisplayDurations" -> .15];
Import["anim.gif", "Animation"]
Run Code Online (Sandbox Code Playgroud)

以下是错误列表:

ArrayPad::depth: Padding amount {{40,0},{40},{0}} should specify padding in no more than the number of dimensions in array {{1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.996078,0.984314,<<142>>},<<49>>,<<145>>}. >>

Image::imgarray: The specified argument ArrayPad[{{1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.996078,0.984314,<<142>>},<<49>>,<<145>>},{{40,0},{40},{0}},{1,1,1}] should be an array of rank 2 or 3 with machine-sized numbers. >>

ImageForwardTransformation::imginv: Expecting an image or graphics instead of Image[ArrayPad[{{1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.996078,0.984314,<<142>>},<<49>>,<<145>>},{<<1>>},{1,1,1}]]. >>

General::stop: Further output of ImageForwardTransformation::imginv will be suppressed during this calculation. >>

Rasterize::bigraster: Not enough memory available to rasterize ImageForwardTransformation expression. >>

General::stop: Further output of Rasterize::bigraster will be suppressed during this calculation. >>
Run Code Online (Sandbox Code Playgroud)

我在Linux下使用Mathematica 8.

Dr.*_*ius 5

我想我明白了.

上面的代码用于彩色图像(3个通道),似乎你试图在黑白图像(1通道)上运行它.

要么使用彩色图像,要么将第二行替换为:

b = Image@ArrayPad[ImageData@a, {{40, 0}, {40}}, 1];
Run Code Online (Sandbox Code Playgroud)

以下是使用上述替换的图像的结果:

a = Binarize[Image["path/file.png"]]
b = Image@ArrayPad[ImageData@a, {{40, 0}, {40}}, 1];
Run Code Online (Sandbox Code Playgroud)

替代文字