Skip to content

Image Crop Comparator (ICC): A research-oriented, interactive image crop comparator for pixel-level method analysis, designed for a fast and flexible interactive workflow with multi-ROI selection, multi-image preview, automatic layout arrangement, and rich customization options.

License

Notifications You must be signed in to change notification settings

Yangzhichen763/ImageCropComparator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

 

Image Crop Comparator (AI generated logo)

โœจ Image Crop Comparator

Image Crop Comparator (ICC): A research-oriented, interactive image crop comparator for pixel-level method analysis, designed for a fast and flexible interactive workflow with multi-ROI selection, automatic layout arrangement, and rich customization options.

Gradio Spaces Demo

Image Crop Comparator Demo

Image Crop Comparator Demo

Overview ๐Ÿ“Œ

Features โœจ

  • ROI-based multi-image previewer for image restoration (or other else) tasks
  • Fast and flexible multi-ROI selection via keyboard- and mouse-shortcut, with undo/redo support
  • Automatic layout arrangement (left / right / top / bottom)
  • Support for multiple workspace structures
  • Highly customizable CLI for future research, and a user-friendly Web interface (gradio) for improved experience

News ๐Ÿ†•

  • 2025.12.30 A quick demo of our tool is available on Hugging Face. ๐Ÿค—
  • 2025.12.30 Update Web version, a Gradio-based UI, providing better user experience for broader users. ๐Ÿš€
  • 2025.12.29 Update basic tutorial. ๐Ÿงพ
  • 2025.12.28 Update ICC-CLI original-version, a runnable command-line (CLI) tool, including local/external sources, ROI selection, layout preview, and export. ๐ŸŽˆ

Contents ๐Ÿ“‘

Getting Started ๐Ÿš€

Installation ๐Ÿงฐ

  • Python 3.8+
  • requirements.txt pins opencv-python==4.7.* and numpy==1.26.*; install with pip install -r requirements.txt.
  • Packages: opencv-python, numpy, natsort, Pillow
# Conda (recommended)
conda create -n crop-comparer python=3.10 -y  # python>=3.8 (e.g. 3.9) is also supported, and python<=3.12 is recommended
conda activate crop-comparer
pip install -r requirements.txt
venv alternative
python -m venv .venv
source .venv/bin/activate  # Windows: .venv\\Scripts\\activate
pip install -r requirements.txt

Quick Start (CLI) ๐Ÿš€

python compare.py
  • Local mode (default) expects the example datasets under examples/; adjust Root/Structure in the UI if using your own layout.

Quick Start (Gradio) ๐Ÿš€

python gradio_app.py
  • Runs the Gradio UI locally on http://127.0.0.1:7860/ by default.
  • Local mode (default) expects the example datasets under examples/; adjust Root/Structure in the UI if using your own layout.

Workspace Layout ๐Ÿ—‚๏ธ

(for default local source) Methods live under the workspace root, and each holds datasets.

<root>/
  <method>/
    <dataset>/
      <images...>
Example
examples/         # <root>
  A-Net/          # <method>
    LOL-v2-real/  # <dataset>
      00698.png   # <images...>
      00775.png
    SDSD-indoor/
      00101.png
      00259.png
  B-Former/
    LOL-v2-real/
      00698.png
      00775.png
    SDSD-indoor/
      00101.png
      00259.png
  ...
Supported structures (use `--structure`)
  • group-dataset-pair: <root>/<method>/<group>/<dataset>/<pair>/<img>.png
  • group-dataset (default classic): <root>/<method>/<group>/<dataset>/<img>.png
  • dataset-only: <root>/<method>/<dataset>/<img>.png
  • flat: <root>/<method>/<img>.png
  • shared: <root>/<image-id>/<method>.png
  • auto (default): tries the above in order.
Structure examples
  1. group-dataset-pair (deep): <root>/<method>/<group>/<dataset>/<pair>/<img>.png
<root>/
  <method1>/
    <group>/
      <dataset>/
        <pair>/
          <img1.png>
          <img2.png>
          ...
          <imgn.png>
  <method2>/
    <group>/
      <dataset>/
        <pair>/
          <img1.png>
          <img2.png>
          ...
          <imgn.png>
  1. group-dataset (default classic): <root>/<method>/<group>/<dataset>/<img>.png
<root>/
  <method1>/
    <group>/
      <dataset>/
        <img1.png>
        <img2.png>
        ...
        <imgn.png>
  <method2>/
    <group>/
      <dataset>/
        <img1.png>
        <img2.png>
        ...
        <imgn.png>
  1. dataset-only: <root>/<method>/<dataset>/<img>.png (example of current default for local source)
<root>/
  <method1>/
    <dataset>/
      <img1.png>
      <img2.png>
      ...
      <imgn.png>
  <method2>/
    <dataset>/
      <img1.png>
      <img2.png>
      ...
      <imgn.png>
  1. flat (images directly under method): <root>/<method>/<img>.png
<root>/
  <method1>/
    <img1.png>
    <img2.png>
    ...
    <imgn.png>
  <method2>/
    <img1.png>
    <img2.png>
    ...
    <imgn.png>
  1. shared (per-image folders contain per-method files): <root>/<image-id>/<methodA>.png, <methodB>.png, ...
<root>/
  <img1>/
    <method1.png>
    <method2.png>
    ...
    <methodn.png>
  <img2>/
    <method1.png>
    <method2.png>
    ...
    <methodn.png>
  1. auto (default): tries the above in order until images are found.

User Guidance ๐Ÿงญ

Tutorials ๐Ÿงช

Quick tutorial

Short walkthrough showing ROI selection.

Basic operations
Basic ROI operations
Select ROI Move ROI Add ROI
Select ROI Move ROI Add ROI
Reselect ROI Delete ROI
Reselect ROI Delete ROI
Layout directions
Layout left Layout right Layout top Layout bottom
Layout left Layout right Layout top Layout bottom
Layout capacities
Single ROI (one) Two ROIs Three ROIs More than three ROIs
Layout one Layout two Layout three Layout more
Mouse-only quick tour

Optional mouse-only quick tour (all operations by mouse): Mouse-only operations (optional)

Interaction ๐ŸŽฎ

Keyboard
Key Action
a Add new ROI
1โ€“9 Add / select ROI by id; Tapping active id to reselect
Shift+1โ€“9 Duplicate active ROI to target id or copy its size
d Add ROI with active size
โ† โ†‘ โ†’ โ†“ Change layout direction
z / y Undo / redo
Enter Switch dataset (group/dataset or dataset)
Space Jump to image by name
n / p Next / previous image
s Save outputs
i Toggle idle (hide/show grids)
r Clear all ROIs
q / Esc Quit

Note: Arrow keys (โ† โ†‘ โ†’ โ†“) control the layout direction, not ROI movement. ROI movement is performed by mouse dragging in position mode.

Mouse
  • Draw in selection mode; drag to reposition in position mode.
  • Hold Shift while drawing a ROI: constrain to a square using the longer side.

Quick actions:

  • Right-click on overlapping ROIs: cycle to the next higher id in that stack (wraps to smallest).
  • Right-click outside any ROI: add the next ROI (same as a).
  • Right-click down inside a ROI, release after the cursor leaves that ROI: delete it.
  • Middle-button inside the active ROI: duplicate it to a new ROI, then drag the new ROI while holding.
  • Middle-button inside a non-active ROI: copy the active ROI size to that ROI (Shift+digit).

Usage ๐Ÿงญ

Local images with auto-discovery:

python compare.py --source local --root <root> --group <group> --dataset <dataset> --layout right
External datasets

External (video-form) datasets require methods.txt:

python compare.py --source external --dataset SDSD-indoor --pair pair13 --layout left

CLI Options โš™๏ธ

Core switches
  • --source: local or external
  • --root: workspace root (local)
  • --group, --dataset, --pair: dataset selectors
  • --structure: layout of files (see above)
  • --output: output root directory
Display and layout
  • --layout: left|top|right|bottom
  • --columns: grid columns for per-ROI previews
  • --magnify / --scale: display-only magnification (ignored for multi-ROI final)
  • --layout-padding: padding between crops and base image
  • --display-thickness-mult: overlay thickness multiplier for final layout
Interaction defaults
  • --mode: selection|position|idle
  • --preview: method key for final preview (GT/input if present)
  • --thickness: ROI and crop border thickness
Logging
  • --log-level: debug|info|warn|error
  • --no-color: disable ANSI colors

Output ๐Ÿ’พ

On s, outputs are written to:

<output>/<timestamp>/<dataset>/<image-basename>/
  orig_<method>.png
  final_<method>.png
  crop_roi<id>_<method>.png

Each method writes its own originals, composed final previews, and all crops for active ROIs.

Reference โš™๏ธ

Logs ๐ŸŽจ

  • Linux terminals show colored status messages: info (cyan), success (green), warnings (yellow), errors (red), notes (bright cyan).
  • Toggle with --no-color; set verbosity via --log-level.

Troubleshooting ๐Ÿ› ๏ธ

Issue:

cv2.error: OpenCV(4.7.0) /io/opencv/modules/highgui/src/window.cpp:1266: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvDestroyAllWindows'

Solution:

  1. uninstall opencv-python-headless and reinstall opencv-python:
    pip uninstall opencv-python-headless
    pip install "opencv-python==4.7.*"
  2. If operation system is Linux, ensure GTK is installed:
    sudo apt-get install libgtk2.0-dev pkg-config

Call to Action โญ

  • โญ If you like ICC, give it a star. It helps others discover the project and supports its growth.

About

Image Crop Comparator (ICC): A research-oriented, interactive image crop comparator for pixel-level method analysis, designed for a fast and flexible interactive workflow with multi-ROI selection, multi-image preview, automatic layout arrangement, and rich customization options.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages