Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
install:
#install commands
pip install --upgrade pip &&\
pip install -r requirements.txt


2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,5 @@ Let your code shine — only the best get merged! 🌟
---

Let me know if you want a badge section, table of contents, or any visuals (like a logo or banner) added to this README as well!


Binary file added pixel_peep/db.sqlite3
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 6 additions & 0 deletions pixel_peep/image_trace/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.contrib import admin
from .models import OriginalImageModel
# Register your models here.

admin.site.register(OriginalImageModel)

6 changes: 6 additions & 0 deletions pixel_peep/image_trace/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class ImageTraceConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'image_trace'
21 changes: 21 additions & 0 deletions pixel_peep/image_trace/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 5.2 on 2025-04-24 10:27

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='OriginalImageModel',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('image_uploaded', models.ImageField(upload_to='original_images')),
],
),
]
Empty file.
Binary file not shown.
Binary file not shown.
10 changes: 10 additions & 0 deletions pixel_peep/image_trace/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.db import models

# Create your models here.

class OriginalImageModel(models.Model):
id = models.AutoField(primary_key= True)
image_uploaded = models.ImageField(upload_to= 'original_images')



3 changes: 3 additions & 0 deletions pixel_peep/image_trace/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
15 changes: 15 additions & 0 deletions pixel_peep/image_trace/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.urls import path
from . import views
from django.conf import settings
from django.conf.urls.static import static


urlpatterns = [
path('', views.image_similarity_upload, name='image-similarity'),
path('img-upload/', views.upload_image_to_db, name='image-upload'),
path('detect-org-img/', views.optimised_solution, name='detect-original-img'),

] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)



86 changes: 86 additions & 0 deletions pixel_peep/image_trace/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
from django.shortcuts import render
from .models import OriginalImageModel
import cv2
from skimage.metrics import structural_similarity as ssim
import numpy as np

# Create your views here.


def upload_image_to_db(request):
''' upload original image into database'''

if request.method == 'POST':
image_data = request.FILES['image-data']

image = OriginalImageModel(image_uploaded = image_data)
image.save()
return render(request,'images_upload.html', {'message':'Image successfully stored inside Db'})
return render(request,'images_upload.html')


def image_similarity_upload(request):
return render(request, 'edited_img_upload.html')


def optimised_solution(request):
''' > The uploaded image is fetched and compared with all original images stored in the database.
> Image comparison is performed pixel-by-pixel using openCV and the scikit-image library.
> Both images are read using OpenCV.

> The comparison based on Structural Similarity Index (SSIM), which extracts 3 key features from an image:
Luminance, Contrast, Structure.
> Comparison between the two images is performed on the basis of these 3 features.

> SSIM computes a similarity score between the two images, ranging from 0 to 1:
> score of 1 indicates the images are identical or highly similar.
> score of 0 indicates the images are completely different.

> All images and their corresponding SSIM scores are stored in a list. From this list,
images with a similarity score of 0.9 or higher are selected.
> Among these, the image with highest score selected. Return the Image alongwith similarity score.

'''

if request.method == 'POST':
duplicate_img = request.FILES['duplicate-image']
img1 = cv2.imdecode(np.frombuffer(duplicate_img.read(), dtype= np.uint8), cv2.IMREAD_GRAYSCALE)

# image resize
dimension = (2500, 2500)
img_1 = cv2.resize(img1, dimension)

# fetch all original img from db
original_images = OriginalImageModel.objects.all()

score = []
for original in original_images:
with open(original.image_uploaded.path, 'rb') as db_img:
img2 = cv2.imdecode(np.frombuffer(db_img.read(), dtype= np.uint8), cv2.IMREAD_GRAYSCALE)
img_2 = cv2.resize(img2, dimension)

ssim_score, dif = ssim(img_1, img_2, full= True)
score.append((ssim_score, original.image_uploaded.url))

filterd_score = [s for s in score if s[0]>= 0.9]

if filterd_score:
high_similarity_image = max(filterd_score, key=lambda i: i[0])

return render(request, 'home_page.html', {'similarity_score':high_similarity_image[0], 'image': high_similarity_image[1]})

return render(request, 'home_page.html', {'message':'Matching Image Not found'})

return render(request, 'home_page.html')












22 changes: 22 additions & 0 deletions pixel_peep/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pixel_peep.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
main()
Binary file added pixel_peep/media/original_images/download_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pixel_peep/media/original_images/goat-life.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pixel_peep/media/original_images/img1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pixel_peep/media/original_images/jailer.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pixel_peep/media/original_images/madhara.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pixel_peep/media/original_images/naruto.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pixel_peep/media/original_images/onep.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pixel_peep/media/original_images/severance.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
16 changes: 16 additions & 0 deletions pixel_peep/pixel_peep/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for pixel_peep project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pixel_peep.settings')

application = get_asgi_application()
130 changes: 130 additions & 0 deletions pixel_peep/pixel_peep/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
"""
Django settings for pixel_peep project.

Generated by 'django-admin startproject' using Django 5.2.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.2/ref/settings/
"""

from pathlib import Path
import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-)cnc-idn)2=$cyjogkemd*92i#^g%4s=75xm7bv8dfzjp__lvb'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'image_trace',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'pixel_peep.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'pixel_peep.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}


# Password validation
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/5.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.2/howto/static-files/

STATIC_URL = 'static/'

STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
# Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
23 changes: 23 additions & 0 deletions pixel_peep/pixel_peep/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
URL configuration for pixel_peep project.

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/5.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
path('admin/', admin.site.urls),
path('', include("image_trace.urls")),
]
16 changes: 16 additions & 0 deletions pixel_peep/pixel_peep/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for pixel_peep project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pixel_peep.settings')

application = get_wsgi_application()
Loading