Creating Custom Color Palette from Image

Suppose you have an image that was created in another package, and you would like to replicate the color palette used in the image within EnSight? Well, EnSight can easily accept custom Color Palettes (see UserManual). The only “tough” part is getting from original image file the RGB values used and into a form of the EnSight Color Palette (.cpal) file. Well, guess what, Python (and more specifically EnVe) can be used to grab out the color legend information, and create your own color palette file (.cpal) for EnSight.

So, how you go about doing this:

1. Start with an image created in another package, which has a color legend. Crop the image to just the color legend palette. You now have an image file which has (in this example) a vertical specification of the color palette.

2. Use the attached python routine below on this file image file. This python routine uses EnVe to query the image file for the RGB values of the pixels in the image, and grab those values off, and write out an EnSight Color Palette file (.cpal) with the appropriate information in it. (If your image has a horizontal legend, then you can switch the x,y values around to perform the same operation).

3. You can thus create a new EnSight Color Palette File (.cpal) from the original image created in another package. EnSight has a limit of 21 bands, but handles 16 colors per band for smooth palette range.

 

As always, please contact us here at CEI should you have any questions, comments, having trouble, or would like routines this customized to your needs. We are here to help.

Click here for Color Palette Create Tool

 

Projected or Frontal Area Calculation

 

 

 

In EnSight, you can easily obtain the area of a set of elements with the EleSize function. You can even get the area in a particular Direction by multiplying it by the Normal and extracting out the component.

However, one particularly useful functionality is to get the “projected” area of a set of elements, or “frontal area”. In this method, overlapping faces do not contribute to the frontal area, and need to be accounted for. I’ve been asked on a few occasions to make something like this work.

This technique modifies the background in EnSight to black, the target elements to white, and uses EnVe to count up the number of white pixels. The routine then does this with an element of fixed/known area, and then it approximates the projected area of the target elements.


Attached is an example Python routine. Please open it up and read through it. There are few User Requirements and caveats at the top of the routine that you should be aware of. It is an approximation using pixel count. In my example model with a prescribed known target size, and my frontal area error is less than 0.01%. This value will differ depending upon the complexity of the geometry and the pixel-to-geometry accuracy at ~8000×8000 resolution.

With slight modification, this routine can be used in batch (add in the model load and part selection).

Click here to download frontal_area Python Script

 

Side by Side Animations

As an engineer working with multiple solutions, or comparing multiple variables, it is quite useful to be able to compare images side by side, but also animations side by side. Image comparison side by side is quite easily done with Word, or Powerpoint, or even image viewers. However, the comparison of multiple animations in a side by side layout is not quite so straight forward. Sure, there are probably some fancy, and/or expensive options out there for video editing, but there is a simpler solution —- EnVe from EnSight.

Given two animations of equal length (number of frames), EnVe’s multiple tiled movie format (.mtm) can be utilized to place two animations side by side, and a new single animation created.

Here are two example animations:

Case 1 AVI

Case 2 AVI

These two animations are each 826 pixels in X, and 574 pixels in Y, and each are 30 frames. In this example of side-by-side, both animations should be the same height (but could vary in width). You can also place the animations one on top of the other, in which case you’d want to have the animations the same width, but could vary each heights.

A Simple “Multiple Tiled Movie Format” file (.mtm) contains information about how to arrange these two animations together. Here is what that file looks like:

MTM 1.0
#
# This is a Multi-Tile Movie file.
#

nummovies 2

fullresolution 1652 574

movie
   imageoffset 0 0
   format AVI
   file Case1.avi

movie
   imageoffset 826 0
   format AVI
   file Case2.avi

You can see above that we set the total number of movies, and the total dimensions of the two movies together (1652 x 574). For each movie, you can therefore set the offset (from the lower left corner). Movie #1 will have a zero offset in X and Y, while Movie #2 will be offset by 826 pixels in X.

You can read this .mtm file into EnVideo, and view a live playing of two animation files, or you can read the .mtm file into EnVe, and simply save out a new single animation file which will have both animations playing side by side. This works great to control the comparison of different models, results, or different variables from separate single animations. Given the flexibility of the .mtm file, you can tile many animations together to make a multiple animation comparison easily and without cost.

Please see below a link which has the animation files, mtm file, and the combined movie example.

Multiple Animation Example

Please see the attached PDF file for similar other operations that can be performed using EnVe… Using EnVe to Create a Single Movie from Existing Movies that Play Simultaneously