I am trying to find the most efficient way to generate a series of images based on a number of input variables. The output should be a series of "zones" connected by "channels" to a central region in the middle. I want to be able to enter the number of zones I want to use, and have the image automatically created with the zones and channels properly spaced within the image.
I have attempted to do this in python using the opencv library: although I have it working it is just a dumb brute force method. Can anyone provide some ideas on how to automate this code so the image is generated just from the input variables? Essentially looping over the # of zones while creating the zones and channels within the loop?
Here's the code I used to create the 3 zone version shown above:
img = np.zeros((500,500),np.uint8)
img = cv2.bitwise_not(img)
img = cv.fromarray(img)
channel_width = 10
channel_length = 75
zones = 3
zone_width = 40
zone_thickness = 4
channel_thickness = 4
h = img.rows; w = img.cols;#,w,z = img.shape
# center
Xc = h/2
Xc0 = int(round(Xc - zone_width/2))
Yc = w/2
Yc0 = int(round(Yc - zone_width/2))
cv.Rectangle(img,(Xc0,Yc0), (Xc0+zone_width,Yc0+zone_width),
cv.RGB(0,0,0),zone_thickness,8)
#zones to left
x0 = int(round(Xc-1.5*zone_width-channel_length))
y0 =int(round(Yc-zone_width/2))
x1 =int(round(Xc -zone_width/2 - channel_length))
y1 = int(round(Yc + zone_width/2))
cv.Rectangle(img,(x0,y0),(x1,y1),cv.RGB(0,0,0),zone_thickness,8)
#left channel
cx0 = int(round(Xc0)) #int(round(Xc0-1.5*zone_width-channel_length))
cy0 = int(round(Yc0 + zone_width/2 - channel_width/2))
cx1 = int(round(Xc0 - channel_length))
cy1 = int(round(Yc0 + zone_width/2 + channel_width/2))
cv.Rectangle(img,(cx0,cy0),(cx1,cy1),cv.RGB(0,0,0),channel_thickness,8)
cv.Rectangle(img,(cx0+2*zone_thickness,cy0),(cx1-2*zone_thickness,cy1),
cv.RGB(255,255,255),-1,8)
#zones to top
x0 = int(round(Xc-.5*zone_width))
y0 =int(round(Yc-1.5*zone_width - channel_length))
x1 =int(round(Xc + zone_width/2 ))
y1 = int(round(Yc - zone_width/2 - channel_length))
cv.Rectangle(img,(x0,y0),(x1,y1),cv.RGB(0,0,0),zone_thickness,8)
#top channel
cx0 = int(round(Xc0 + zone_width/2 - channel_width/2))
#int(round(Xc0-1.5*zone_width-channel_length))
cy0 = int(round(Yc0 ))
cx1 = int(round(Xc0 + zone_width/2 + channel_width/2))
cy1 = int(round(Yc0 -channel_length))
cv.Rectangle(img,(cx0,cy0),(cx1,cy1),cv.RGB(0,0,0),channel_thickness,8)
cv.Rectangle(img,(cx0,cy0+2*zone_thickness),(cx1,cy1-2*zone_thickness),
cv.RGB(255,255,255),-1,8)
#zones to right
x0 = int(round(Xc+1.5*zone_width+channel_length))
y0 =int(round(Yc-zone_width/2))
x1 =int(round(Xc +zone_width/2 + channel_length))
y1 = int(round(Yc + zone_width/2))
cv.Rectangle(img,(x0,y0),(x1,y1),cv.RGB(0,0,0),zone_thickness,8)
#right channel
cx0 = int(round(Xc0+zone_width)) #int(round(Xc0-1.5*zone_width-channel_length))
cy0 = int(round(Yc0 + zone_width/2 - channel_width/2))
cx1 = int(round(Xc0 +zone_width + channel_length))
cy1 = int(round(Yc0 + zone_width/2 + channel_width/2))
cv.Rectangle(img,(cx0,cy0),(cx1,cy1),cv.RGB(0,0,0),channel_thickness,8)
cv.Rectangle(img,(cx0-2*zone_thickness,cy0),(cx1+2*zone_thickness,cy1),
cv.RGB(255,255,255),-1,8)