This repository contains solutions to three problem statements involving image processing and multithreading in Python.
Given the image input.jpg and mask mask.png, create the image result.jpg.
- Code in Python
- Resulting image
- Place
input.jpgandmask.pngin theimagesfolder. - Run the script:
python create_image.py
- The resulting image
result.jpgwill be saved in theimagesfolder.
| Input | Mask | Result |
|---|---|---|
![]() |
![]() |
![]() |
Write a Python code to launch 3 different threads with the following behavior:
- Each thread should print every 5 seconds:
Thread <thread number> is running at <time elapsed>. - Initially start thread 1 and 3.
- After 20 seconds, stop thread 1 and start thread 2.
- After another 18 seconds, stop thread 3 and start thread 1.
- Code in Python
- Run the script:
python multithreading.py
Given a query image (query.jpg) and a database folder of jpg images, find the image in the database folder that is most visually similar to the query image.
- Code in Python
- Most similar image to query image
- Install the required libraries: Ensure you have all the necessary Python libraries installed. You can install them using pip:
pip install torch torchvision pillow numpy scikit-learn matplotlib
- Save the script: Save the provided code into a Python file, for example, similar_image_search.py.
- Prepare your dataset: Ensure you have a folder with images for creating the feature matrix.
- Run the script: Use the command line to run the script in either 'create' or 'search' mode.
To create a feature matrix from a dataset of images, run:
python similar_image_search.py --mode create --dataset /path/to/your/dataset --output /path/to/save/feature_matrix.pkl
Replace /path/to/your/dataset with the path to your dataset folder and /path/to/save/feature_matrix.pkl with the desired output file path.
To search for similar images using a query image, run:
python similar_image_search.py --mode search --output /path/to/save/feature_matrix.pkl --query /path/to/query/image.jpg
Replace /path/to/save/feature_matrix.pkl with the path to the saved feature matrix file and /path/to/query/image.jpg with the path to your query image.
# Create feature matrix
python similar_image_search.py --mode create --dataset ./images --output ./feature_matrix.pkl
# Search similar images
python similar_image_search.py --mode search --output ./feature_matrix.pkl --query ./query_image.jpgMake sure to adjust the paths according to your file structure.



