To utilize the image reading portion of the phase-field module VTK must be enabled when building libMesh. If the MOOSE environment package was installed (see Getting Started) this may be easily accomplished by using the following commands:
module load advanced_modules module load vtk-clang cd ~/projects/moose/scripts ./update_and_rebuild_libmesh.sh --with-vtk-include=$VTKINCLUDE_DIR --with-vtk-lib=$VTKLIB_DIR
If you are using a custom build of VTK then the above include and lib directories simply must be altered to use the correct location for your build.
It is also possible to set the
VTK_DIR environmental variables in your
.bash_profile with the aforementioned directories, then utilize the
--enable-vtk flag when running the build script rather including the directories explicitly.
ImageFunctionin your input file.
[Functions] [./my_image] type = ImageFunction file = example.png [../] 
uvariable and create an initial mesh as shown in Figure 2.
[ICs] [./u_ic] type = FunctionIC function = my_image variable = u [../] 
The example image shown is 20 by 20 pixels as is the mesh (20 by 20 elements) to which the initial condition is applied. This IS NOT a requirement, in fact the main reason for building the
ImageFunction object was to enable an arbitrary mesh geometry to be able to sample the image and adapt accordingly.
Beginning with a 2 by 2 element mesh and adding the following Adaptivity block, which includes initial adaptivitiy, to the input file results in the mesh shown Figure 3.
[Adaptivity] max_h_level = 5 initial_steps = 5 initial_marker = marker [./Indicators] [./indicator] type = GradientJumpIndicator variable = u [../] [../] [./Markers] [./marker] type = ErrorFractionMarker indicator = indicator refine = 0.9 [../] [../] 
Image stacks or 3D images (see Supported File Types section for more details) are also supported. For example, consider as set of images named example_00.png, example_01.png, ..., and example_19.png. To read these images the syntax below is used in the
ImageFunction block. Again, using this data as an initial condition and using initial adaptivity, as shown above, results in the mesh shown in Figure 4. It is also possible to limit the reader to a set of images using the
file_range parameter, which may be set to a single value to read a single image or a range (e.g.,
file_range = '00 10') to read a subset of the images.
[Functions] [./my_image] type = ImageFunction file_base = example_ file_type = png [../] 
The VTK library includes a range of image filters and processing tools, some basic processing tools are included. However, a derivative class could easily be developed to expand upon these capabilities.
Currently, the three types of processing are applied in the order shown below.
By default, the RGB pixel data is converted into a single greyscale value representing the magnitude. This is accomplished using the vtkImageMagnitude class.
It is possible to select a single component rather than using the magnitude by setting the
component parameter in the input file to a valid component number, which will be 0, 1 or 2 for RGB images.
Basic thresholding is accomplished using the vtkImageThreshold class. Thresholding requires three parameters be set in the input file:
threshold: The threshold value to consider.
upper_value: Image data above the threshold are replaced with this value.
lower_value: Image data below the threshold are replaced with this value.
It is possible to shift and scale the image data, this is accomplished using the vtkImageShiftScale object. The
shift input parameter adds the given value to the image data and
scale input parameter multiplies the image data by the supplied value.
The order of application of the shift and scale are dictated by the VTK object, the documentation states: "Pixels are shifted (a constant value added) and then scaled (multiplied by a scalar)."
Flipping an image along the major axis directions x, y, or z is performed using vtkImageFlip object. Three flags exists---
flip_z---which may be set in any combination.
By default, the image actual physical dimensions are set to the dimensions of the mesh. However, it is possible to set the dimensions of the image independently from using the
dimensions input parameters.
This allows for flexibility to how the
ImageFunction is utilized. For example, a mesh could be defined to domain that is smaller than the actual image. Thus, if the
ImageFunction dimensions are set to the larger domain, the mesh would only sample some portion of the image. Effectively, this feature can work on a cropped image, without needing to create a separate cropped image.
Currently, two types of files are supported *.tif and *.png. However, *.tif files often to no read correctly with VTK, depending on the format of the file. So, if you experience problems reading *.tif files it may require changing the format to *.png. This can easily be done with any number of tools with ImageMagick being one of the most powerful.
A range of tests that implement each of the aforementioned features are included in the phase-field module tests directory: