class PAGE:
def __init__(self, direction_bins, h=None, w=None):
def load_img(self, img_file=None, img_array=None):
def init_kernel(self, mu_1, mu_2, sigma_1, sigma_2, S1, S2):
def apply_kernel(self, sigma_LPF, thresh_min, thresh_max, morph_flag):
def create_page_edge(self):
def run(self, img_file, mu_1, mu_2, sigma_1, sigma_2, S1, S2,\
sigma_LPF, thresh_min, thresh_max, morph_flag):
-
To instantiate a
PAGE
class, three parametersh
(height),w
(width), anddirection_bins
are needed.h
andw
are set toNone
by default. If you leave them asNone
by default, their value will be determined when calling the followingload_img
method. -
The
load_img
method can load the image from either an image file indicated byimg_file
or an image array indicated byimg_array
. Then it converts the image to greyscale if it is in RGB format, ifh
andw
are not indicated in the__init__
method, they will be determined by the shape of the image. Otherwise, the image will be reshaped to the indicated size. -
The
init_kernel
method initializes the PAGE kernel according to the parametersmu_1
,mu_2
,sigma_1
,sigma_2
,S1
,S2
. In the CPU version, kernels for different frequency bins are initialized in serial. As for the derivation of the kernel and the physical meaning of parameters, please refer to references [9], [10]. -
The
apply_kernel
method first denoises the loaded image with a low-pass filter characterized bysigma_LPF
, then it applies the initialized kernel to the denoised image, finally it applies morphological operation ifmorph_flag==1
. The thresholds in the morphological operation are indicated bythresh_min
andthresh_max
. -
The
create_page_edge
method creates a weighted color image of PAGE output to visualize directionality of edges. -
The
run
method wrapsload_img
,init_kernel
,apply_kernel
,create_page_edge
together.
The GPU version of PST significantly accelerates the PST algorithm by using GPU(s). As defined in phycv/page_gpu.py
, the architect of the PAGE_GPU
class is similar to the original PAGE
class with same attributes and methods. The main differences are:
- You have to indicate the
device
(in a PyTorch fashion) when instantiating the class. - Image IO is done by
torchvision
instead ofopencv
, matrix operation is done bytorch
instead ofnumpy
- The
init_kernel
method initializes kernels for different direction bins in parallel by using broadcasting. - The
apply_kernel
method applies kernels for different direction bins to the image in parallel by using broadcasting. - The returned result locates on GPU and is in the form of
torch.Tensor
.
Example 1 - Single Image ( scripts/run_page.py
)
In this example, we run PAGE on a single image and all steps are performed in a single run
method.
Example 2 - Video ( scripts/run_page_video.py
)
In this example, we run PAGE on a video, when using fixed parameters for all frames, the init_kernel
can be called only once to save computation time. Note that running this script takes some time because saving processed results and putting them together to generate a video is time-consuming.