| 1 |
import math |
|---|
| 2 |
import sys |
|---|
| 3 |
|
|---|
| 4 |
# Tweakable parameters |
|---|
| 5 |
wedge_start = 80 # Width of wedge at the narrower point |
|---|
| 6 |
wedge_end = 2000 # Width of wedge at the broader point |
|---|
| 7 |
number_of_bands = 11 # Number of alternating bands (must be odd) |
|---|
| 8 |
size_of_image_x = 2000 # Size of the image (X) |
|---|
| 9 |
size_of_image_y = 2000 # Size of the image (Y) |
|---|
| 10 |
pixel_sampling = 1.0 * Units.A # Pixel width |
|---|
| 11 |
threshold = 2.0 * Units.A # Threshold for low pass filtering |
|---|
| 12 |
amplitude = 255 # amplitude of the obscillations |
|---|
| 13 |
|
|---|
| 14 |
# Image is created |
|---|
| 15 |
image=CreateImage(Size(size_of_image_x,size_of_image_y)) |
|---|
| 16 |
image.CenterSpatialOrigin() |
|---|
| 17 |
image.SetSpatialSampling(pixel_sampling) |
|---|
| 18 |
|
|---|
| 19 |
# For a cleaner code, 4 shorthands are defined |
|---|
| 20 |
image_extent=image.GetExtent() |
|---|
| 21 |
start_y=image_extent.GetStart()[1] |
|---|
| 22 |
end_y=image_extent.GetEnd()[1] |
|---|
| 23 |
start_x=image_extent.GetStart()[0] |
|---|
| 24 |
end_x=image_extent.GetEnd()[0] |
|---|
| 25 |
|
|---|
| 26 |
# Wedge is written in the image |
|---|
| 27 |
for y in range (start_y,end_y+1): |
|---|
| 28 |
wedge_width=wedge_start+(y-start_y)*(wedge_end-wedge_start)/(end_y-start_y) |
|---|
| 29 |
for x in range (start_x,end_x+1): |
|---|
| 30 |
half_wedge=wedge_width/2.0 |
|---|
| 31 |
outer_bands=(number_of_bands-1)/2 |
|---|
| 32 |
factor=(0.5+outer_bands)*math.pi/half_wedge |
|---|
| 33 |
if float(x)>-half_wedge and float(x)<half_wedge: |
|---|
| 34 |
value=255*math.cos(float(x)*factor) |
|---|
| 35 |
image.SetReal(Point(x,y),value) |
|---|
| 36 |
|
|---|
| 37 |
# Image is low-pass filtered |
|---|
| 38 |
filter=alg.GaussianLowPassFilter(threshold) |
|---|
| 39 |
image.ApplyIP(filter) |
|---|
| 40 |
|
|---|
| 41 |
# Image is saved |
|---|
| 42 |
SaveImage(image,sys.argv[1]) |
|---|
| 43 |
|
|---|
| 44 |
# Viewer is launched to show the result |
|---|
| 45 |
Viewer(image) |
|---|