Recolored Image Detection Via A Deep Discriminative Model: P.Yugandhar Sharma 1304-21-862-024
Recolored Image Detection Via A Deep Discriminative Model: P.Yugandhar Sharma 1304-21-862-024
1.INTRODUCTION
Image re-coloring is a technique that can transfer image color or theme and result in an imperceptible change in human eyes.
Although image re-coloring is one of the most important image manipulation techniques, there is no special method designed
for detecting this kind of forgery. In this paper, we propose a trainable end-to-end system for distinguishing re-colored images
from natural images. The proposed network takes the original image and two derived inputs based on illumination consistency
and inter-channel correlation of the original input into consideration and outputs the probability that it is recolored. Our
algorithm adopts a CNN-based deep architecture, which consists of three feature extraction blocks and a feature fusion module.
To train the deep neural network, we synthesize a dataset comprised of re-colored images and corresponding ground truth using
different re-coloring methods. Extensive experimental results on the recolored images generated by various methods show that
Disadvantages:
• Accuracy is low
• Low efficiency
Proposed System
We use three feature extractors and a feature fusion module to learn forgery-relevant features. We adopt
the original image as one of the input branches like traditional neural networks. Additionally, we derive
DI(Difference image) and Illumination Image (IM) as two pieces of evidence of image recolored
detection based on the observations that images may not maintain the inter-channel correlation or
illuminant consistency after the recoloring process. These two pieces of evidence are employed as two
additional input branches together with the original image.
Advantages:
• Accuracy is high
Scope of the project
“The scope of recolored image detection via a deep discriminative model is quite broad and can be
applied to various domains and scenarios.Detecting recolored images using a deep discriminative
model involves training a neural network to distinguish between original and altered images based
on color changes. The model learns to capture patterns indicative of recoloring, enabling it to
classify new images as either original or recolored.By using advanced deep learning techniques,
such as convolutional neural networks (CNNs), it's possible to train models to recognize recolored
images. Such technology could have applications in detecting image manipulation and ensuring the
authenticity of visual content, which can be valuable in various fields, including forensics, media
verification, and digital image authentication.
SOFTEWARE REQUIREMENTS
For developing the application, the following are the Software Requirements:
Python
Django
Mysql
Wampserver
HARDWARE REQUIREMENTS
For developing the application the following are the Hardware Requirements:
RAM: 256 MB
1. Upload Image: This module allows the user to upload an image that needs to be analyzed for recoloring. The image can be
in various formats such as JPEG, PNG, or GIF. Once the image is uploaded, it serves as input for the subsequent modules.
2. Color Transfer: The Color Transfer module is responsible for transferring the color scheme from the uploaded image to a
reference image or a predefined color palette. This process involves extracting the color distribution from the source image
and applying it to the target image. Color transfer techniques ensure that the recolored image maintains a similar color
appearance to the original image.
3. Image State: After the color transfer, the Image State module analyzes the resulting recolored image. It leverages a deep
discriminative model, which is a machine learning model trained to classify images based on their characteristics. The
module uses the trained model to assess the state of the recolored image and determine if any modifications or
manipulations have been applied.
4. Show Image: The Show Image module is responsible for displaying the recolored image and its corresponding state or
classification. It presents the output to the user, allowing them to observe the changes made during the color transfer and the
analysis performed by the deep discriminative model. The module may include additional visualizations or overlays to
highlight specific regions or features of interest.
Functional requirements
Data Collection: Collect appropriate picture data containing both indoor and outdoor pictures which contain the objects of all the types and preferentially
containing various colors.
Recoloring Algorithm: Use an appropriate recoloring algorithm for creating a dataset for training the model.
Data Pre-processing:
• Importing the dataset.
• Categorizing the training images into Recolored (0) Original (1)
• Optimize images such that all are of same size.
Exploratory Data Analysis: It involves extraction of necessary features important for training the model.
Training and Evaluating Model:
• The model must be trained using any efficient algorithm and API so that results are accurate and train the model for number of iterations to maintain
accuracy.
• The model has to be evaluated continuously for each iteration and training has to be continued until the results are consistent and saving the results.
Testing the Model: The model has to be applied to a new data set for testing the accuracy
Feasibility Study:
The feasibility of the project is analyzed in this phase and business proposal is put forth with a very general plan for the project
and some cost estimates. During system analysis the feasibility study of the proposed system is to be carried out. This is to ensure
that the proposed system is not a burden to the company. For feasibility analysis, some understanding of the major requirements
for the system is essential.
• Economic Feasibility
• Technical Feasibility
• Social Feasibility
Economic Feasibility:
This study is carried out to check the economic impact that the system will have on the
organization. The amount of fund that the company can pour into the research and
development of the system is limited. The expenditures must be justified. Thus the developed
system as well within the budget and this was achieved because most of the technologies used
are freely available. Only the customized products had to be purchased.
Technical Feasibility:
This study is carried out to check the technical feasibility, that is, the technical requirements of the system. Any system
developed must not have a high demand on the available technical resources. This will lead to high demands on the available
technical resources. This will lead to high demands being placed on the client. The developed system must have a modest
requirement, as only minimal or null changes are required for implementing this system.
Social Feasibility:
The aspect of study is to check the level of acceptance of the system by the user. This includes the process of training the user
to use the system efficiently. The user must not feel threatened by the system, instead must accept it as a necessity. The level of
acceptance by the users solely depends on the methods that are employed to educate the user about the system and to make him
familiar with it. His level of confidence must be raised so that he is also able to make some constructive criticism, which is
welcomed, as he is the final user of the system.
Design:
Architecture
DATA FLOW DIAGRAM
In software engineering, a class diagram in the Unified Modeling Language (UML) is a type of static structure diagram that
describes the structure of a system by showing the system's classes, their attributes, operations (or methods), and the
relationships among the classes. It explains which class contains information.
USECASE DIAGRAM:
showImage
SEQUENCE DIAGRAM :-
User Application
A sequence diagram in Unified Modeling
uploadImage
Language (UML) is a kind of interaction diagram
that shows how processes operate with one another colorTransfer
and in what order. It is a construct of a Message
imageState
Sequence Chart. Sequence diagrams are sometimes
called event diagrams, event scenarios, and timing
showImage
diagrams.
Activity Diagram :
#!/usr/bin/env python
# coding: utf-8
# As we were not having dataset of all colored and recolored images, we created our own dataset of colored and recolored
images
# In[1]:
import numpy as np
import cv2
# ## Transfer Color
# Input a *source* and *target* image. The color space of *source* image is transferred to the color space of *target*
image.
# In[2]:
(l, a, b) = cv2.split(target)
# substarct the means from target image
l -= lMeanTar
a -= aMeanTar
b -= bMeanTar
l = (lStdTar/lStdSrc)*l
a = (aStdTar/aStdSrc)*a
b = (bStdTar/bStdSrc)*b
l += lMeanSrc
a += aMeanSrc
b += bMeanSrc
# clipping the pixels between 0 and 255
l = np.clip(l, 0, 255)
a = np.clip(a, 0, 255)
b = np.clip(b, 0, 255)
# merge the channels
transfer = cv2.merge([l, a, b])
# converting back to BGR
transfer = cv2.cvtColor(transfer.astype("uint8"), cv2.COLOR_LAB2BGR)
return transfer
# ## Calculating Image Statistics
# The mean and standard deviation of the L, a, b channels of both source and target images.
# In[3]:
def image_stats(image):
(l, a, b) = cv2.split(image)
# ## Display Images
# In[5]:
show_image("Transfer", transfer)
cv2.waitKey(0)
# In[7]:
import numpy
import cv2
mypath1='Image_Dataset/source/'
mypath2='Image_Dataset/target/'
print(len(onlyfiles1))
print(len(onlyfiles2))
images1[n]=cv2.resize(images1[n],(500,500))
# transfer of color
# display of image
show_image("Source", images1[n])
show_image("Target",images2[n] )
show_image("Transfer", transfer)
cv2.waitKey(0)
import numpy
import cv2
import os
# In[6]:
mypath1='Image_Dataset/source/'
mypath2='Image_Dataset/target/'
print(len(onlyfiles1))
print(len(onlyfiles2))
images1[n]=cv2.resize(images1[n],(500,500))
images2[n]=cv2.resize(images2[n],(500,500))
# transfer of color
path1='Image_Dataset/original'
# display of image
#show_image("Source", images1[n])
#show_image("Target",images2[n] )
#show_image("Transfer", transfer)
cv2.waitKey(0)
# In[7]:
IMAGE_SIZE=(IMAGE_WIDTH, IMAGE_HEIGHT)
IMAGE_CHANNELS=3 # RGB color
# ## Prepare Traning Data
# In[10]:
import os
filenames = os.listdir("Image_Dataset/training_set")
categories = []
for filename in filenames:
category = filename.split('.')[0]
if category == 'original_color':
categories.append(1)
else:
categories.append(0)
df = pd.DataFrame({ 'filename': filenames, 'category': categories})
# In[11]:
df.head()
# In[12]:
df.tail()
# In[13]:
df['category']=df['category'].astype(str)
# In[14]:
df.dtypes
# In[15]:
#see sample image
sample = random.choice(filenames)
image = load_img("Image_Dataset/training_set/"+sample)
plt.imshow(image)
# In[16]:
# see total in counts
df['category'].value_counts().plot.bar()
# In[17]:
from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D, Dropout, Flatten, Dense, Activation, BatchNormalization
model = Sequential()
model.add(Conv2D(64, (3, 3), activation='relu', input_shape=(IMAGE_WIDTH, IMAGE_HEIGHT, IMAGE_CHANNELS)))
model.add(BatchNormalization())
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Conv2D(64, (3, 3), activation='relu'))
model.add(BatchNormalization())
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Conv2D(64, (3, 3), activation='relu'))
model.add(BatchNormalization())
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(64, activation='relu'))
model.add(BatchNormalization())
model.add(Dropout(0.5))
model.add(Dense(1, activation='sigmoid'))
model.summary()
# ## callback
# In[18]:
# ## Early Stop
# To prevent over fitting we will stop the learning after 10 epochs and val_loss value not decreased
# In[19]:
earlystop = EarlyStopping(patience=10)
# ## Learning Rate Reduction
# We will reduce the learning rate when then accuracy not increase for 2 steps
# In[20]:
learning_rate_reduction = ReduceLROnPlateau(monitor='val_acc',
patience=2,
verbose=1,
factor=0.5,
min_lr=0.00001)
# In[21]:
callbacks = [earlystop, learning_rate_reduction]
# ## prepared train and test dataset
# In[22]:
train_df, validate_df = train_test_split(df, test_size=0.20, random_state=42)
train_df = train_df.reset_index(drop=True)
validate_df = validate_df.reset_index(drop=True)
# In[23]:
total_train = train_df.shape[0]
total_validate = validate_df.shape[0]
batch_size=4
# In[24]:
print(train_df.shape)
print(validate_df.shape)
# In[25]:
train_df['category'].value_counts().plot.bar()
# ## Traning Generator
# In[26]:
train_datagen = ImageDataGenerator(
rotation_range=15,
rescale=1./255,
shear_range=0.1,
zoom_range=0.2,
horizontal_flip=True,
width_shift_range=0.1,
height_shift_range=0.1
# In[27]:
train_generator = train_datagen.flow_from_dataframe(
train_df,
"Image_Dataset/training_set",
x_col='filename',
y_col='category',
target_size=IMAGE_SIZE,
class_mode='binary',
batch_size=batch_size
)
# ## Validation Generator
# In[28]:
validation_datagen = ImageDataGenerator(rescale=1./255)
validation_generator = validation_datagen.flow_from_dataframe(
validate_df,
"Image_Dataset/training_set",
x_col='filename',
y_col='category',
target_size=IMAGE_SIZE,
class_mode='binary',
batch_size=batch_size
)
# ## Fit Model
# In[29]:
history = model.fit_generator(
train_generator,
epochs=epochs,
validation_data=validation_generator,
validation_steps=total_validate//batch_size,
steps_per_epoch=total_train//batch_size,
callbacks=callbacks
)
# In[30]:
model.save_weights("model.h5")
# ## Virtualize Training
# In[31]:
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(12, 12))
ax1.plot(history.history['loss'], color='b', label="Training loss")
ax1.plot(history.history['val_loss'], color='r', label="validation loss")
ax1.set_xticks(np.arange(1, epochs, 1))
ax1.set_yticks(np.arange(0, 1, 0.1))
ax2.plot(history.history['accuracy'], color='b', label="Training accuracy")
ax2.plot(history.history['val_accuracy'], color='r',label="Validation accuracy")
ax2.set_xticks(np.arange(1, epochs, 1))
legend = plt.legend(loc='best', shadow=True)
plt.tight_layout()
plt.show()
# In[32]:
test_filenames = os.listdir("Image_Dataset/testing_set")
test_df = pd.DataFrame({
'filename': test_filenames
})
nb_samples = test_df.shape[0]
# In[33]:
test_gen = ImageDataGenerator(rescale=1./255)
test_generator = test_gen.flow_from_dataframe(
test_df,
"Image_Dataset/testing_set",
x_col='filename',
y_col=None,
class_mode=None,
target_size=IMAGE_SIZE,
batch_size=batch_size,
shuffle=False
# ## Predict
# In[34]:
# As predicted of binary classification result return probability that image likely to be a original. So we will have threshold 0.5 which
mean if predicted value more than 50% it is a original and under 50% will be a recolor.
# In[35]:
threshold = 0.5
test_df['probability'] = predict
# In[36]:
test_df['category'].value_counts().plot.bar()
# In[37]:
sample_test = test_df.head(8)
sample_test.head()
plt.figure(figsize=(12, 24))
filename = row['filename']
category = row['category']
probability = row['probability']
img = load_img("Image_Dataset/testing_set/"+filename, target_size=IMAGE_SIZE)
plt.subplot(6, 3, index+1)
plt.imshow(img)
plt.xlabel(filename + '(' + "{}".format(category) + ')' '(' + "{}".format(round(probability, 2)) + ')')
plt.tight_layout()
plt.show()
# In[38]:
#submission
submission_df = test_df.copy()
submission_df['id'] = submission_df['filename'].str.split('.').str[0]
submission_df['label'] = submission_df['category']
submission_df.drop(['filename', 'category'], axis=1, inplace=True)
submission_df.to_csv('submission.csv', index=False)
# In[ ]:
# training size=46
# testing size=8
# we achieved acc: 0.6944
# val_acc: 0.6667
# testing accuracy: out of 8 unknown images 6 are correctly classified and 2 missclassified see following results.
# probability id label
# 0.64807886 original_color 1
# 0.007113604 original_color 0
# 0.013637688 original_color 0
# 0.71749115 original_color 1
# 0.39750034 recolor 0
# 0.01088892 recolor 0
# 0.2330829 recolor 0
# 0.03004521 recolor 0
SCREENSHOTS
To run project double click on ‘run.bat’ then application will display lots of images so you close all those images and
then CNN start training and after training will get below screen
Then will get below submission.csv file as output
Image Comparison
Orginal Image
Modified Image
Difference Image
Thresh
Result
Test
6.SYSTEM TESTING
The purpose of testing is to discover errors. Testing is the process of trying to discover every conceivable fault or weakness in a
work product. It provides a way to check the functionality of components, sub assemblies, assemblies and/or a finished product It is
the process of exercising software with the intent of ensuring that the Software system meets its requirements and user expectations
and does not fail in an unacceptable manner. There are various types of test. Each test type addresses a specific testing requirement.
Bottom up approach
• As shown in the following figure of Black box testing, we are not thinking of the internal
workings, just we think about
• What is the output to our system?
• What is the output for given input to our system?
The Black box is an imaginary box that hides its internal workings
• White box testing is concerned with testing the implementation of the program. The intent
of structural is not to exercise all the inputs or outputs but to exercise the different
programming and data structure used in the program. Thus structural testing aims to
achieve test cases that will force the desire coverage of different structures. Two types of
path testing are statement testing coverage and branch testing coverage.
Different levels of testing are used in the testing process, each level of testing aims to test
different aspects of the system. The basic levels are:
• Unit testing
• Integration testing
• Functionality testing
• System testing
• User Acceptance testing
UNIT TESTING
UT01 Check for the user to upload Unit testing Provide a sample image file The image should be successfully uploaded Confirm if the function indeed uploads Pass
an valid image and processed by the system. the image as expected.
UT02 Checking for Transferring Unit testing Provide a source image and a The color from the source image is Verify if the color transfer operation is Pass
Color from Source to Target target image successfully transferred to the target image, performed correctly.
and the resulting image is displayed.
UT03 Checking the determination of Unit testing Provide an image to the "Image The image state correctly determines Confirm if the function accurately Pass
image state State" module whether the image is in the original color or identifies the image state.
recolored.
UT04 Checking the image display Unit testing Provide an image to the "Show The show Image should display the provided Verify if the image is displayed as Pass
functionality. Image” image on the screen expected.
module
TEST Test case Testing Steps to Expected Actual Result
Type
CASE ID Description Execute Result Result
IT01 Check that when an Integration Upload a source image and The color of the source Record the actual Pass
image is uploaded and testing upload a target image and image should be result of the upload
the color transfer is Verify that the color transfer transferred to the target process and the actual
performed, the color process takes place without image, and the result state of images after
transfer function errors. should be displayed color transfer.
correctly processes the without errors
uploaded image
IT02 Ensure that the image Integration Upload a source image and The image should be Record the the actual Pass
state is correctly testing target image, Perform color correctly classified as state of images after
determined based on transfer and Verify that the either original or color transfer and
the color transfer image state (original or recolored, and it should be actual result of image
process, and the image recolored) is correctly displayed accordingly display.
is displayed determined and Display the
accordingly. image based on its state.
TEST Test case Testing Type Steps to Expected Actual Result
FT02 Transfer color from a Functionality Provide a source image and a The system should successfully Verify that the color Pass
source image to a target Testing target image and transfer the color from the source has been transferred
image. Trigger the color transfer image to the target image and the correctly and the result
process resulting image should reflect the matches expectations.
color transfer
FT03 Verify the accuracy of the Functionality A set of known recolored The system achieves a high Result is displayed pass
recolored image detection Testing images accuracy rate in detecting recolored
images, with results close to the
training accuracy.
TEST Test case Testing Type Steps to Expected Actual Result
ST02 Check that the system can display SYSTEM Upload multiple images (original or The system should display all uploaded images The original or recolored images Pass
multiple images simultaneously. TESTING recolored) and simultaneously, allowing users to compare them are displayed
View all uploaded images within the
system
UAT01 Evaluate the accuracy of the trained USER Check the accuracy graph the model correctly identifies recolored images as It displays and record graph Pass
model using test images ACCEPTANCE either original or recolored and record the accuracy
TESTING accuracy.
In this work, we present a novel deep learning approach for re colored image detection. Both the inter-
channel correlation and the illumination consistency are employed to help the feature extraction. We
elaborate the design principle of our RecDeNet and systematically validate the rationality by running a
number of experiments. Furthermore, two recolored datasets with different sources are created and the
high performance of our RecDeNet demonstrates the effectiveness of the model. We hope our simple yet
effective RecDeNet will serve as a solid baseline and help future research in re colored images detection.
Our future work will focus on designing a more effective network architecture and searching for some
high-level cues for better distinguishing
6.FUTURE ENHANCEMENT
The training set is comprised of images recolored using one algorithm, hence results of the
network may not be very accurate for all recolored images. So, in future the training dataset
will have to be enhanced by using images formed using different algorithms. The dependent
variables in the training of the system can be increased to improve accuracy. An application
can be built using this network to dynamically upload a picture and know genuineness of
image. This network can be attuned to hardware devices so to check a scanned image