使用Mathematica进行图像处理

时间:2011-01-22 15:46:33

标签: linux wolfram-mathematica

我在my previous post之后创建了这个主题。我无法运行以下代码(由@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"]

以下是错误列表:

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. >>

我在Linux下使用Mathematica 8。

1 个答案:

答案 0 :(得分:5)

我想我明白了。

上面的代码适用于彩色图像(3个通道),似乎您正试图在B&amp; W图像(1个通道)上运行它。

使用彩色图像或将第二行替换为:

b = Image@ArrayPad[ImageData@a, {{40, 0}, {40}}, 1];

以下是使用上述替代品的图片的结果:

a = Binarize[Image["path/file.png"]]
b = Image@ArrayPad[ImageData@a, {{40, 0}, {40}}, 1];

alt text