def __call__(self, **params_to_override): p = ParamOverrides(self, params_to_override) xsize, ysize = SheetCoordinateSystem(p.bounds, p.xdensity, p.ydensity).shape xsize, ysize = int(round(xsize)), int(round(ysize)) xdisparity = int(round(xsize * p.xdisparity)) ydisparity = int(round(xsize * p.ydisparity)) dotsize = int(round(xsize * p.dotsize)) bigxsize = 2 * xsize bigysize = 2 * ysize ndots = int( round(p.dotdensity * (bigxsize + 2 * dotsize) * (bigysize + 2 * dotsize) / min(dotsize, xsize) / min(dotsize, ysize))) halfdot = floor(dotsize / 2) # Choose random colors and locations of square dots random_seed = p.random_seed np.random.seed(random_seed * 12 + random_seed * 99) col = np.where(np.random.random((ndots)) >= 0.5, 1.0, -1.0) np.random.seed(random_seed * 122 + random_seed * 799) xpos = np.floor(np.random.random( (ndots)) * (bigxsize + 2 * dotsize)) - halfdot np.random.seed(random_seed * 1243 + random_seed * 9349) ypos = np.floor(np.random.random( (ndots)) * (bigysize + 2 * dotsize)) - halfdot # Construct arrays of points specifying the boundaries of each # dot, cropping them by the big image size (0,0) to (bigxsize,bigysize) x1 = xpos.astype(numpy.int) x1 = choose(less(x1, 0), (x1, 0)) y1 = ypos.astype(numpy.int) y1 = choose(less(y1, 0), (y1, 0)) x2 = (xpos + (dotsize - 1)).astype(numpy.int) x2 = choose(greater(x2, bigxsize), (x2, bigxsize)) y2 = (ypos + (dotsize - 1)).astype(numpy.int) y2 = choose(greater(y2, bigysize), (y2, bigysize)) # Draw each dot in the big image, on a blank background bigimage = zeros((bigysize, bigxsize)) for i in range(ndots): bigimage[y1[i]:y2[i] + 1, x1[i]:x2[i] + 1] = col[i] result = p.offset + p.scale * bigimage[ (ysize / 2) + ydisparity:(3 * ysize / 2) + ydisparity, (xsize / 2) + xdisparity:(3 * xsize / 2) + xdisparity] for of in p.output_fns: of(result) return result
def _set_image(self,image): # Stores a SheetCoordinateSystem with an activity matrix # representing the image if not isinstance(image,numpy.ndarray): image = array(image,Float) rows,cols = image.shape self.scs = SheetCoordinateSystem(xdensity=1.0,ydensity=1.0, bounds=BoundingBox(points=((-cols/2.0,-rows/2.0), ( cols/2.0, rows/2.0)))) self.scs.activity=image
def __call__(self,**params_to_override): p = ParamOverrides(self,params_to_override) shape = SheetCoordinateSystem(p.bounds,p.xdensity,p.ydensity).shape result = p.scale*ones(shape, Float)+p.offset self._apply_mask(p,result) for of in p.output_fns: of(result) return result
def __call__(self, **params_to_override): p = ParamOverrides(self, params_to_override) shape = SheetCoordinateSystem(p.bounds, p.xdensity, p.ydensity).shape result = self._distrib(shape, p) self._apply_mask(p, result) for of in p.output_fns: of(result) return result
def _setup_xy(self,bounds,xdensity,ydensity,x,y,orientation): """ Produce pattern coordinate matrices from the bounds and density (or rows and cols), and transforms them according to x, y, and orientation. """ self.debug(lambda:"bounds=%s, xdensity=%s, ydensity=%s, x=%s, y=%s, orientation=%s"%(bounds,xdensity,ydensity,x,y,orientation)) # Generate vectors representing coordinates at which the pattern # will be sampled. # CB: note to myself - use slice_._scs if supplied? x_points,y_points = SheetCoordinateSystem(bounds,xdensity,ydensity).sheetcoordinates_of_matrixidx() # Generate matrices of x and y sheet coordinates at which to # sample pattern, at the correct orientation self.pattern_x, self.pattern_y = self._create_and_rotate_coordinate_arrays(x_points-x,y_points-y,orientation)