Skip to content

Commit

Permalink
Merge pull request #6 from encord-team/fhv/all_image_features
Browse files Browse the repository at this point in the history
Compute all image features.
  • Loading branch information
Gorkem-Encord authored Aug 12, 2022
2 parents ee941a2 + eb53a57 commit e8087ab
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions pocs/img_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,46 @@ def rank_by_blur(image):
return 1 - cv2.Laplacian(image, cv2.CV_64F).var()


options = {
"contrast": (rank_by_contrast, "Contrast"),
"green": (rank_by_green, "Greenness"),
"red": (rank_by_red, "Redness"),
"blue": (rank_by_blue, "Blueness"),
"brightness": (rank_by_brightness, "Brightness"),
"sharpness": (rank_by_sharpness, "Sharpness"),
"blurriness": (rank_by_blur, "Blurriness"),
}


@hydra.main(version_base=None, config_path="../conf", config_name="config")
def main(cfg: DictConfig):
cache_dir, project = fetch_project_info(cfg)
iterator = DatasetIterator(project, cache_dir, use_images=True, subset_size=100)
iterator = DatasetIterator(project, cache_dir, use_images=True, subset_size=-1)

# When you log stuff, this will be stored in the `pocs/outputs` directory.

# Preprocessing happens here.
# You can build/load databases of embeddings, compute statistics etc,
# ...

with CSVIndexWriter(cache_dir, iterator, prefix="brightness-indexer") as writer:
for data_unit, img_pth in tqdm(iterator.iterate(), desc="Iterating data units", total=len(iterator)):
key = iterator.get_identifier()
for rank_fn, name in options.values():
with CSVIndexWriter(cache_dir, iterator, prefix=f"{name}-indexer") as writer:
for data_unit, img_pth in tqdm(iterator.iterate(), desc=f"Looking for {name}", total=len(iterator)):
key = iterator.get_identifier()

# This is where you do the actual inference.
# This is where you do the actual inference.

# Some convenient properties of the current data.
# ``iterator.label_hash`` the label hash of the current data unit
# ``iterator.du_hash`` the data unit hash of
# ``iterator.frame`` the frame of the current data unit hash of
# ``iterator.num_frame`` the total number of frames in the label row.
# Some convenient properties of the current data.
# ``iterator.label_hash`` the label hash of the current data unit
# ``iterator.du_hash`` the data unit hash of
# ``iterator.frame`` the frame of the current data unit hash of
# ``iterator.num_frame`` the total number of frames in the label row.

# Do your thing (inference)
image = cv2.imread(img_pth.as_posix())
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# Do your thing (inference)
image = cv2.imread(img_pth.as_posix())
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

writer.write_score(key, rank_by_brightness(image), "Brightness")
writer.write_score(key, rank_fn(image), "")


if __name__ == '__main__':
Expand Down

0 comments on commit e8087ab

Please sign in to comment.