# how can i expand this gabor patch to the size of the bounding box?

• Last Update :
• Techknowledgy :

Below is the function used to generate the code. The code was ported from this tutorial for Matlab (assume import numpy as np):

def gabor_patch(size, lambda_, theta, sigma, phase, trim = .005):
""
"Create a Gabor Patch

size: int
Image size(n x n)

lambda_: int
Spatial frequency(px per cycle)

theta: int or float
Grating orientation in degrees

sigma: int or float
gaussian standard deviation(in pixels)

phase: float
0 to 1 inclusive
""
"
# make linear ramp
X0 = (np.linspace(1, size, size) / size) - .5

# Set wavelength and phase
freq = size / float(lambda_)
phaseRad = phase * 2 * np.pi

# Make 2 D grating
Xm, Ym = np.meshgrid(X0, X0)

# Change orientation by adding Xm and Ym together in different proportions
thetaRad = (theta / 360.) * 2 * np.pi
grating = np.sin(((Xt + Yt) * freq * 2 * np.pi) + phaseRad)

# 2 D Gaussian distribution
gauss = np.exp(-((Xm ** 2) + (Ym ** 2)) / (2 * (sigma / float(size)) ** 2))

# Trim
gauss[gauss < trim] = 0

return grating * gauss

Suggestion : 2

The way to achieve what I want is to set the sigma parameter to something bigger, as this will broaden the "spread" of the gaussian, thereby exposing more of the sine texture., 1 week ago This resulted in a bounding box that has five-slices depth. The collected labeled data was converted into the required input format of the deep learning framework we used. ... In multiple patch clamp setup it can be used to describe the connectome at cellular level. We presented DIGAP’s application to brain research, but other fields, such as ... , The reason it extends farther on one side is it needs to cover the section line. Put a text or a dimension in the view on another side and you will see the bold box extends to include them as well. 02-03-2019 01:53 PM , 6 days ago Sep 16, 2016  · Bounding box of the stamp is then decided by local threshold based heuristic method. Stamp detection performance is measured as an average Intersection over Union (IoU) overlap between the box markings obtained from the crowd-sourcing experiment and ones which are estimated algorithmically. We get an average IoU overlap of 74.81% which ...

def gabor_patch(size, lambda_, theta, sigma, phase, trim = .005): ""
"Create a Gabor Patch     size : int         Image size (n x n)     lambda_ : int         Spatial frequency (px per cycle)     theta : int or float         Grating orientation in degrees     sigma : int or float         gaussian standard deviation (in pixels)     phase : float         0 to 1 inclusive     "
""
# make linear ramp X0 = (np.linspace(1, size, size) / size) - .5 # Set wavelength and phase freq = size / float(lambda_) phaseRad = phase * 2 * np.pi # Make 2 D grating Xm, Ym = np.meshgrid(X0, X0) # Change orientation by adding Xm and Ym together in different proportions thetaRad = (theta / 360.) * 2 * np.pi Xt = Xm * np.cos(thetaRad) Yt = Ym * np.sin(thetaRad) grating = np.sin(((Xt + Yt) * freq * 2 * np.pi) + phaseRad) # 2 D Gaussian distribution gauss = np.exp(-((Xm ** 2) + (Ym ** 2)) / (2 * (sigma / float(size)) ** 2)) # Trim gauss[gauss < trim] = 0
return grating * gauss
def gabor_patch(size, lambda_, theta, sigma, phase, trim = .005): ""
"Create a Gabor Patchsize : int  Image size (n x n)lambda_ : int  Spatial frequency (px per cycle)theta : int or float  Grating orientation in degreessigma : int or float  gaussian standard deviation (in pixels)phase : float  0 to 1 inclusive"
""
# make linear rampX0 = (np.linspace(1, size, size) / size) - .5 # Set wavelength and phasefreq = size / float(lambda_) phaseRad = phase * 2 * np.pi # Make 2 D gratingXm, Ym = np.meshgrid(X0, X0) # Change orientation by adding Xm and Ym together in different proportionsthetaRad = (theta / 360.) * 2 * np.piXt = Xm * np.cos(thetaRad) Yt = Ym * np.sin(thetaRad) grating = np.sin(((Xt + Yt) * freq * 2 * np.pi) + phaseRad) # 2 D Gaussian distributiongauss = np.exp(-((Xm ** 2) + (Ym ** 2)) / (2 * (sigma / float(size)) ** 2)) # Trimgauss[gauss < trim] = 0
return grating * gauss

Suggestion : 3

A set of Gabor filters with different frequencies and orientations may be helpful for extracting useful features from an image.[8] In the discrete domain, two-dimensional Gabor filters are given by, ,Some authors claim that simple cells in the visual cortex of mammalian brains can be modeled by Gabor functions.[2][3] Thus, image analysis with Gabor filters is thought by some to be similar to perception in the human visual system. ,Gabor filter for image processing and computer vision (demonstration),2-D Gabor filters have rich applications in image processing, especially in feature extraction for texture analysis and segmentation.[9] f {\displaystyle f} defines the frequency being looked for in the texture. By varying θ {\displaystyle \theta } , we can look for texture oriented in a particular direction. By varying σ {\displaystyle \sigma } , we change the support of the basis or the size of the image region being analyzed.

import numpy as np

def gabor(sigma, theta, Lambda, psi, gamma):
""
"Gabor feature extraction."
""
sigma_x = sigma
sigma_y = float(sigma) / gamma

# Bounding box
nstds = 3 # Number of standard deviation sigma
xmax = max(abs(nstds * sigma_x * np.cos(theta)), abs(nstds * sigma_y * np.sin(theta)))
xmax = np.ceil(max(1, xmax))
ymax = max(abs(nstds * sigma_x * np.sin(theta)), abs(nstds * sigma_y * np.cos(theta)))
ymax = np.ceil(max(1, ymax))
xmin = -xmax
ymin = -ymax(y, x) = np.meshgrid(np.arange(ymin, ymax + 1), np.arange(xmin, xmax + 1))

# Rotation
x_theta = x * np.cos(theta) + y * np.sin(theta)
y_theta = -x * np.sin(theta) + y * np.cos(theta)

gb = np.exp(-.5 * (x_theta ** 2 / sigma_x ** 2 + y_theta ** 2 / sigma_y ** 2)) * np.cos(2 * np.pi / Lambda * x_theta + psi)
return gb
function gb = gabor_fn(sigma, theta, lambda, psi, gamma)

sigma_x = sigma;
sigma_y = sigma / gamma;

%
Bounding box
nstds = 3;
xmax = max(abs(nstds * sigma_x * cos(theta)), abs(nstds * sigma_y * sin(theta)));
xmax = ceil(max(1, xmax));
ymax = max(abs(nstds * sigma_x * sin(theta)), abs(nstds * sigma_y * cos(theta)));
ymax = ceil(max(1, ymax));
xmin = -xmax;
ymin = -ymax;
[x, y] = meshgrid(xmin: xmax, ymin: ymax);

%
Rotation
x_theta = x * cos(theta) + y * sin(theta);
y_theta = -x * sin(theta) + y * cos(theta);

gb = exp(-.5 * (x_theta. ^ 2 / sigma_x ^ 2 + y_theta. ^ 2 / sigma_y ^ 2)).*cos(2 * pi / lambda * x_theta + psi);
import Data.Complex
gabor λ θ ψ σ γ x y = exp(-(x '^2 + γ^2 * y' ^ 2) / (2 * σ ^ 2)) * exp(i * (2 * pi * x '/λ + ψ))
where x ' =  x * cos θ + y * sin θ
y ' = -x * sin θ + y * cos θ
i = 0: +1

Suggestion : 4

Create a crop window from a random position in the image. Crop the image and bounding box to the same crop window.,To increase the size of the sample datastores, replicate the file names of the image and the bounding box and labels.,Read the first image and its associated box label from the combined datastore.,Display the cropped and resized image and bounding box.

filenameImage = 'kobi.png';
bbox = [4 156 1212 830];
label = "dog";
annotatedImage = insertShape(I, "rectangle", bbox, "LineWidth", 8);
imshow(annotatedImage)
title('Original Image and Bounding Box')
scale = 1 / 2;
J = imresize(I, scale);
bboxResized = bboxresize(bbox, scale);
annotatedImage = insertShape(J, "rectangle", bboxResized, "LineWidth", 8);
imshow(annotatedImage)
title('Resized Image and Bounding Box')
targetSize = [1024 1024];

Suggestion : 5

Example: Draw heatmaps, segmentation maps, keypoints, bounding boxes, ...,Example: Convert keypoints to distance maps, extract pixels within bounding boxes from images, clip polygon to the image plane, ...,imgaug contains many helper function, among these functions to quickly visualize augmented non-image results, such as bounding boxes or heatmaps.,Many helper functions Example: Draw heatmaps, segmentation maps, keypoints, bounding boxes, ... Example: Scale segmentation maps, average/max pool of images/maps, pad images to aspect ratios (e.g. to square them) Example: Convert keypoints to distance maps, extract pixels within bounding boxes from images, clip polygon to the image plane, ...

This patch fixes a deprecation warning in
Affine
that would be caused when providing
boolean images and order != 0.
conda config--add channels conda - forge
conda install imgaug
pip install imgaug
pip install git + https: //github.com/aleju/imgaug.git
import numpy as np
import imgaug.augmenters as iaa

# dummy
function, implement this
# Return a numpy array of shape(N, height, width, #channels)
# or a list of (height, width, #channels) arrays(may have different image # sizes).
# Images should be in RGB
for colorspace augmentations.
# Images should usually be in uint8 with values from 0 - 255.
return np.zeros((128, 32, 32, 3), dtype = np.uint8) + (batch_idx % 255)

def train_on_images(images):
# dummy
function, implement this
pass

# Pipeline:
#(1) Crop images from each side by 1 - 16 px, do not resize the results
# images back to the input size.Keep them at the cropped size.
#(2) Horizontally flip 50 % of the images.
#(3) Blur images using a gaussian kernel with sigma between 0.0 and 3.0.
seq = iaa.Sequential([
iaa.Crop(px = (1, 16), keep_size = False),
iaa.Fliplr(0.5),
iaa.GaussianBlur(sigma = (0, 3.0))
])

for batch_idx in range(100):
train_on_images(images_aug)