Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image search #368

Open
The-Bart-The opened this issue Jan 5, 2024 · 3 comments
Open

Image search #368

The-Bart-The opened this issue Jan 5, 2024 · 3 comments

Comments

@The-Bart-The
Copy link

No description provided.

Copy link
Member

Hello! How can I assist you with image search on GitHub?

@The-Bart-The
Copy link
Author

Say I have an image, dimensions 800 pixels by 100 pixels, and a second image, dimensions 800 pixels by 2000 pixels. How can I efficiently detect if the first image matches the bottom 100 pixels of the second image? I would like to do this programmatically in a Windows *.BAT file, possibly using ImageMagick.

Copy link
Member

To detect if the first image matches the bottom 100 pixels of the second image programmatically, you can use ImageMagick's command-line tool called compare.

Here's how you can accomplish this using a Windows .bat file:

  1. Install ImageMagick by downloading the Windows installer from the official website: https://imagemagick.org/script/download.php#windows
  2. Follow the installation wizard to install ImageMagick on your computer.

Once ImageMagick is installed, you can use the following .bat script to compare the images:

@echo off
setlocal

set "first_image=path\to\first_image.png"
set "second_image=path\to\second_image.png"

set /a "second_image_height=2000"
set /a "comparison_height=100"

rem Crop the second image to the desired height
magick "%second_image%" -crop x%comparison_height%+0+%((%second_image_height% - %comparison_height%))% second_crop.png

rem Compare the first image with the cropped second image
magick compare -metric AE "%first_image%" second_crop.png null: 2>&1 | findstr /R /C:"^[0-9]*$" > comparison_result.txt

set /p "comparison_result=" < comparison_result.txt

rem Check if the comparison result is zero (0), indicating a match
if %comparison_result% equ 0 (
    echo "The first image matches the bottom %comparison_height% pixels of the second image."
) else (
    echo "The first image does not match the bottom %comparison_height% pixels of the second image."
)

rem Clean up temporary files
del second_crop.png comparison_result.txt

endlocal

Make sure to replace path\to\first_image.png and path\to\second_image.png in the script with the actual paths to your images.

This script loads the second image, crops it to the desired height using the formula %((%second_image_height% - %comparison_height%))%, compares it with the first image, and outputs the comparison result to a file called comparison_result.txt. The script then reads the comparison result from the file and checks if it is equal to zero (0) to determine if there is a match.

Finally, the script cleans up temporary files, if any.

I hope this helps! Let me know if you have any further questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants