We will be interested in constructing arrays of values that represent
``abstract'' images, abstract in the sense that they will be made
within Mathematica and do not come from real digitilized images.
We will use the Table
command to construct arrays of
values. It can be used to construct arrays of any dimension or
size. To construct a list called mylist using the function
f, we would use the following command:
mylist = Table[N[f[i]],{i,imin,imax}];The variable i is the index for the list and it runs from the values imin to imax, so the array has imax - imin + 1 entries. Note that the ; after the input statement suppresses the output. Note also that we have entered decimal values in the table by using the Mathematica function
N[ ]
to evaluate f.
We can use this command to produce a doubly indexed list, which we should interpret as being a two-dimensional data set obtained by sampling an image. To obtain a two-dimensional data set, we must use a function f of two variables,
mylist = Table[N[f[i,j]],{i,imin,imax},{j,jmin,jmax}];
Let us illustrate how to use the two-dimensional version of the
Table
command to construct a table representing
a function on the domain
.
mylist = Table[N[f[ 4*(i/32), 4*(j/32)]],{i,1,32},{j,1,32}];
We can use functions built up out of standard functions for the function f, for example,
Sin[i-j] Cos[i+j]However, it will be more interesting for us to use continuous functions, like trigonometric functions, to build up piecewise continous functions. In particular, it will be interesting to look at characteristic functions
To do this in Mathematica, we need the following:
/;
in a ``split'' definition of a function.&&
in a split definition of a function.||
in a split definition of a function.
f[x_,y_]:= 1/; x^2 + y^2 <= 4; f[x_,y_]:= 0 /; x^2 + y^2 > 4;This is relatively simple because it is defined by a single condition, the equation of the circle. If a region is defined by more than one condition, it is necessary to use
&&
to represent a logical
``and'' and ||
to represent a logical ``or''. For example, to
define a function that is .5 on a unit square and 0 outside the
square, we could use the following.
f[x_,y_]:=.5/; (x >= 0) && (x<=1) && (y >= 0) && (y<=1); f[x_,y_]:=0/; (x < 0) || (x > 1) || (y < 0) || (y > 1);The first line would be read as f(x,y) = .5 if