Detection Cropping Documentation
This file creates sub-images based on Mega-detector animal detections within the raw observation images.
It is essential, that steps 1 and 2 in the README are completed before this step, as the downloaded raw observation images and the object detection bounding_box.json` file are required for this script's execution.
Attributes:
Name | Type | Description |
---|---|---|
root_path |
str
|
The absolute path to the root of the project directory. |
raw_image_path |
str
|
The complete (absolute + relative) path to the raw image directory. |
processed_image_path |
str
|
The save path for the sub-images pointing to the |
bounding_box_path |
str
|
The path to the |
adapt_name(file_name, detector_count_extension)
This method adapts the name of the raw observation image to include the sub-image suffix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_name |
str
|
The filename of the raw observation image in the format |
required |
detector_count_extension |
str
|
The alphabetical character sub-image extension indicating what sub-image number this is. |
required |
Returns:
Type | Description |
---|---|
str
|
The modified image name to include the sub-image suffix extension. |
Source code in detection_cropping.py
94 95 96 97 98 99 100 101 102 103 104 105 106 |
|
convert_to_coords(array, img)
This method converts the bounding_boxes.json
bbox
values into coordinates used to crop the sub-image
The bbox
JSON dictionary contains the following value:
bbox: [
percentage width of the center of the bounding box,
percentage height of the center of the bounding box,
The percentage width of bounding box. The percentage is calculated as the percentage of the width of the image,
The percentage height of the bounding box. The percentage is calculated as the percentage of the height of the image
]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
array |
List
|
The list of |
required |
img |
Image
|
The raw observation image on which the object detection occurred. |
required |
Returns:
Type | Description |
---|---|
list
|
The list contains the following coordinates: [x_start, x_end, y_start, y_end] to suit the image slicing that produces the cropped image. |
Source code in detection_cropping.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
|
crop_image(detect, img, detection_count, file_name)
This method crops an image based on the bounding box created by Mega-detector.
Each image is assigned a sub-image suffix character to represent the current sub-image number. The sub-image is enhanced through Lanczos Interpolation and edge enhancement kernels to maintain resolution. However, resolution loss still occurs due to the cropping process.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
detect |
JSON dict
|
The current object detection of the observation image (from |
required |
img |
Image
|
The raw observation image in which the objects were detected. |
required |
detection_count |
int
|
The number of sub-images cropped so far. |
required |
file_name |
str
|
The name of the raw image in the format |
required |
Source code in detection_cropping.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
|
enhance_image(cropped_img)
This method attempts to enhance the cropped and resize image through edge enhancement, to ensure that crucial details of the image are not lost.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cropped_img |
Image
|
The cropped and resized (interpolated) image to be enhanced. |
required |
Returns:
Type | Description |
---|---|
Image
|
The edge enhanced image. |
Source code in detection_cropping.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
process_images(bounding_boxes)
Processes each image within the bounding_box.json file and crops them according to the animal detections.
This method iterates through all images, matching each identified object's category to detect when it matches animal (category 1).
When a match occurs, the image is cropped and names
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bounding_boxes |
JSON
|
The JSON format of the bounding_boxes file. |
required |
Source code in detection_cropping.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|