knitr::opts_chunk$set( cache = TRUE )
knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) options( tibble.print_min = 4L, tibble.print_max = 4L ) library( dplyr )
# --- Configuration img_path <- '/Users/Karl/Dropbox/Projects/Video-Captioning/pipelines/box2/' image_filenames <- dir( path=img_path )
The Fixed Camera Surveillance (FCS) Package contains functions to cluster images in various ways, then display similar images together and evaluate which feature extraction and clustering methods work best.
Common tasks for Fixed Camera Surveillance include:
Background Subtraction
Foreground Segmentation
Object Identification
The general approach is:
Extract features from the images, for example, by using HoGs or hashes.
Cluster the images, based on their features
Display images for each cluster in its own collage.
A. Feature extraction
Hashing
a. average
b. phash
c. dhash
d. ( invariant hash compares two images )
HoGs
a. cells
b. bins
B. Clustering 1. K-means
C. Display
images_found <- as.logical( length( image_filenames )) if( !images_found ) cat( sprintf( 'No image files found\n')) if( images_found ){ hashes <- hash_batch( img_path ) all_hashes <- purrr::map( hashes, 2 ) }
if( images_found ){ hashes$names all_hashes[['values']][['files']][1:4] all_hashes[['values']][['hashes']][1:4] }
if( images_found ){ hogs <- hog_batch( IMAGE_PATH = img_path ) all_hogs <- purrr::map( hogs, 2 ) }
if( images_found ){ cat( sprintf( 'Results:\n' )) print( hogs$names ) print( all_hogs[['values']][['files']][1:4] ) print( all_hogs[['values']][['hogs']][1:4] ) }
# 3 cells # | 6 bins # | | hogs3c6b <- OpenImageR::HOG_apply( img_path, cells = 3, orientations = 6 ) get_clusters <- function( data, filenames, algorithm = 'adaptive', N = 2 ){ clusters <- exemplar_image_names <- NULL if( algorithm == 'adaptive' ){ # adaptive clustering clusters <- ADPclust::adpclust( data ) seq( clusters$nclust ) %>% purrr::map_int( ~clusters$centers[ .x ] ) -> indexes } if( algorithm == 'kmeans' ){ # K-means clustering clusters <- kmeans( data, centers = N ) seq( N ) %>% purrr::map_int( ~match( .x, clusters$cluster )) -> indexes } exemplar_image_names <- if( any( grepl( 'indexes', ls() )) ) purrr::map_chr( indexes, ~filenames[ .x ] ) try( if( length( clusters ) > 0 ){ # --- Get the name of the variable used to identify clusters cluster_var <- grep( 'cluster*', names( clusters ), value=TRUE ) # --- Now use the cluster variable to get cluster IDs clusters <- clusters[[ cluster_var ]] } ) list( IDs=clusters, exemplars=exemplar_image_names ) } clustered <- get_clusters( data = hogs3c6b[[ 2 ]] , filenames = image_filenames , algorithm = 'kmeans' , N = 9 ) clustered$IDs clustered$exemplars
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.