Professional Documents
Culture Documents
3
3
7. INTRODUCTION
The objective of this project is to identify fake images(Fake images are the images that are
digitally altered images). The problem with existing fake image detection system is that
they can be used detect only specific tampering methods like splicing, coloring etc. We
approached the problem using machine learning and neural network to detect almost all
kinds of tampering on images.
Using latest image editing software’s, it is possible to make alterations on image which are
too difficult for human eye to detect. Even with a complex neural network, it is not
possible to determine whether an image is fake or not without identifying a common factor
across almost all fake images. So, instead of giving direct raw pixels to the neural network,
we gave error level analysed image.
This project provides two level analysis for the image. At first level, it checks the image
metadata. Image metadata is not that much reliable since it can be altered using simple
programs. But most of the images we come across will have non-altered metadata which
helps to identify the alterations. For example, if an image is edited with Adobe Photoshop,
the metadata will contain even the version of the Adobe Photoshop used.
In the second level, the image is converted into error level analysed format and will be
resized to 100px x 100px image. Then these 10,000 pixels with RGB values (30,000
inputs) is given in to the input layer of Multilayer perceptron network. Output layer contain
two neurons. One for fake image and one for real image. Depending upon the value of
these neuron outputs along with metadata analyser output, we determine whether the image
is fake or not and how much chance is there for the given image to be tampered.
Page | 1
Fraudulent Image Detection
8. Literature Review
This paper presents a method to automatically and efficiently detect face tampering
in videos, and particularly focuses on two recent techniques used to generate hyper-
realistic forged videos: Deepfake and Face2Face. Traditional image forensics techniques
are usually not well suited to videos due to the compression that strongly degrades the data.
Page | 2
Fraudulent Image Detection
Thus, this paper follows a deep learning approach and presents two networks, both with a
low number of layers to focus on the mesoscopic properties of images. We evaluate those
fast networks on both an existing dataset and a dataset we have constituted from online
videos. The tests demonstrate a very successful detection rate with more than 98% for
Deepfake and 95% for Face2Face.
Blind Fake Image detection (Nidhal El Abbadi1 , Adil Mohamad Hassan2 , Mudher
Mohammed AL-Nwany3 1Computer Science Dep., University of Kufa Najaf, Iraq).
Cameras are regarded as trustworthy devices and photos traditionally imply truth.
Nowadays, digital photos have been widely used as historical records and as evidences of
real happenings in applications from journalist reporting, police investigation, law
enforcement, insurance, medical and dental examination, military, and museum to
consumer photography. While digital photos are conveniently used, their credibility has
been severely challenged due to numerous fraudulent cases involving image forgeries, e.g.
the fake results on human stem-cell research
Page | 3
Fraudulent Image Detection
The system requirement is a main part in the analyzing space of the project.
The analyzer of the project has to properly analyze the hardware and software requirement
otherwise in future designer will face more trouble with hardware and software required.
They should specify the correct hardware and software to suit the particular project.
9.2.1 History
The Java platform and language began as an internal project at Sun Microsystems
inDecember 1990, providing an alternative to the C++/C programming languages.
Engineer Patrick Naughton had become increasingly frustrated with the state of Sun's C++
and C application programming interfaces (APIs) and tools. While considering moving to
NeXT, Naughton was offered a chance to work on new technology and thus the Stealth
Page | 4
Fraudulent Image Detection
Page | 5
Fraudulent Image Detection
the cable industry felt that their platform gave too much control to the user and firstperson
lost their bid to SGI. An additional deal with The 3DO Company for a set-top box also
failed to materialize. Unable to generate interest within the TV industry, the company was
rolled back into S
Page | 6
Fraudulent Image Detection
Page | 7
Fraudulent Image Detection
Step 2
Step 3
Page | 8
Fraudulent Image Detection
Step 4
Step 5
Write the following in the command line (cmd.exe):
C:\Users\Your Name>java -version
Page | 9
Fraudulent Image Detection
9.3.MODULE DESCRIPTION
INTRODUCTION
A module is a separate unit of software or hardware. Software is
composed of separate, interchangeable components called modules.
Most image files do not just contain a picture. They also contain information
(metadata) about the picture. Metadata provides information about a picture's pedigree,
including the type of camera used, color space information, and application notes.
Different picture formats include different types of metadata. Some formats, like BMP,
PPM, and PBM contain very little information beyond the image dimensions and color
space. In contrast, a JPEG from a camera usually contains a wide variety of information,
including the camera's make and model, focal and aperture information, and timestamps.
PNG files typically contain very little information, unless the image was converted from a
JPEG or edited with Photoshop. Converted PNG files may include metadata from the
source file format. Metadata provides information related to how the file was generated and
handled. This information can be used to identify if the metadata appears to be from a
digital camera, processed by a graphical program, or altered to convey misleading
information. Common things to look for include:
1) Make, Model, and Software These identify the device or application that
created the picture. Most digital cameras include a Make and Model in the
EXIF metadata block. (However, the original iPhone does not!) The Software
may describe the camera's firmware version or application information.
2) Image size The metadata often records the picture's dimensions. Does the
rendered image size (listed at the bottom of the metadata) match the other sizes
in the metadata? Many applications resize or crop pictures without updating
other metadata fields.
Page | 10
Fraudulent Image Detection
3) Timestamps Look for fields that detail timestamps. These typically identify
when a picture was taken or altered. Do the timestamps match the expected
timeframe?
JPEG is a lossy format, but the amount of error introduced by each resave is not
line. Any modification to the picture will alter the image such that stable areas (no
additional error) become unstable. Fig.1 shows a modified image using Photoshop. The
modified picture was based on the first 75% resave. Books on the shelf were duplicated
and a toy dinosaur was added to the shelf. The 95% ELA identifies the changes since they
are areas that are no longer at their minimal error level. Additional areas of the picture
show slightly more volatility because Photoshop merged information from multiple layers,
effectively modifying many of the pixels.
The process of machine learning is similar to that of data mining. Both systems
search through data to look for patterns. However, instead of extracting data for human
comprehension as is the case in data mining applications machine learning uses that data to
detect patterns in data and adjust program actions accordingly. Machine learning
algorithms are often categorized as being supervised or unsupervised. Supervised
algorithms can apply what has been learned in the past to new data. Unsupervised
algorithms can draw inferences from datasets. Facebook's News Feed uses machine
learning to personalize each member's feed. If a member frequently stops scrolling in order
to read or "like" a particular friend's posts, the News Feed will start to show more of that
friend's activity earlier in the feed. Behind the scenes, the software is using statistical
analysis and predictive analytics to identify patterns in the user's data and use to patterns to
populate the News Feed. They observe the activities of the user like, comment, share etc on
Page | 11
Fraudulent Image Detection
various posts and based on these activities the contents on the news feed will be adjusted
continuously.
Neuroph Studio
Neuroph studio is an open source Java neural network framework that helps to
easily build and use neural networks. It also provides a direct interface for loading images
Metadata-extractor
JavaFX
Page | 12
Fraudulent Image Detection
Metadata Analysis
Most image files do not just contain a picture. They also contain information (metadata) about the
picture. Metadata provides information about a picture's pedigree, including the type of camera
used, color space information, and applicationnotes. Different picture formats include different types
ofmetadata. Some formats, like BMP, PPM, and PBM containvery little information beyond the image
dimensions and colorspace. In contrast, a JPEG from a camera usually contains awide variety of
information, including the camera's make andmodel, focal and aperture information, and timestamps.PNG
files typically contain very little information, unlessthe image was converted from a JPEG
Page | 13
Fraudulent Image Detection
or edited withPhotoshop. Converted PNG files may include metadata fromthe source file
format. Metadata provides information related to how the file was generated and handled.
This information can be used
1) Make, Model, and Software
These identify the device or application that created the picture. Most digital cameras
include a Make and Model in the EXIF metadata block. (However, the original iPhone does not!) The
Software may describe the camera's firmw areversion or application information.
2) Image size
The metadata often records the picture's dimensions. Doesthe rendered image size (listed at the bottom of
the metadata)match the other sizes in the metadata? Many applications resizeor crop pictures without
updating other metadata fields.
3) Timestamps
Look for fields that detail timestamps. These typically identifyy when a picture was taken or altered. Do
thtimestamps matchch the expected timeframe?
4)Types of metadata
There are many different metadata types. Some aonly generatedted by cameras, while others are only
generated by applications.
5) Descriptions
Many pictures include embedded annotations that describe the photo, identify the photographer, or itemize
alteration steps.
6) Missing metadata
Are any metadata fields missing? If the picture came from adigital camera, then it should have camera-
specificinformation. Some applications and online services strip outmetadata. A lack of specific metadata
usually indicates aresaved picture and not an original photo.
7) Altered Metadata
Metadata is analogous to the chain of custody for evidencehanding. It can identify how a picture was
generated, processed, and last saved. However, some people intentionallyalter metadata. They
may edit timestamps or photo informationin an attempt to deceive
Page | 14
Fraudulent Image Detection
Page | 15
Fraudulent Image Detection
human eye to detect small scalechanges to image so that we have decided to use machinelearning to detect
the anomalies in the error level analyzedimages.
C. Machine Learning
The process of machine learning is similar to that of datamining. Both systems search through data to look
for patterns.However, instead of extracting data for human comprehensionas is the case in data mining
applications machine learning usesthat data to detect patterns in data and adjust program
actionsaccordingly. Machine learning algorithms are oftencategorized as being supervised or
unsupervised. Supervisedalgorithms can apply what has been learned in the past to newdata. Unsupervised
algorithms can draw inferences fromdatasets.Facebook's News Feed uses machine learning
to personalize each member's feed. If a member frequently stopsscrolling in order to read or
"like" a particular friend's posts,
the News Feed will start to show more of that friend's activityearlier in the feed. Behind the
scenes, the software is usingstatistical analysis and predictive analytics to identify patternsin the user's data
and use to patterns to populate the News Feed.They observe the activities of the user like, comment, share
etcon various posts and based on these activities the contents onthe news feed will be adjusted continuously.
System testing is actually as series different test whose primary purpose is to full exercise
the computer base system. Where the software and other system elements are tested as
whole. To test computer software, we spiral out along streamlines the broader the scope of
testing with each turn. The last higher-order testing step falls outside the boundary of
software Engineering and in to the broader context of computer system engineering.
Software, once validated, must be combining with order system Elements (e.g. hardware,
people, and databases). System testing verifies that all the elements Mesh properly and that
overall system function/performance is achieved.
Page | 16
Fraudulent Image Detection
Software testing is a critical element of software quality assurance and represents the
ultimate review of specification, design and coding. In fact, testing is the one step in the
software engineering process that could be viewed as destructive rather than constructive.
A strategy for software testing integrates software test case design methods into a well-
planned series of steps that result in the successful construction of software. Testing is
the set of activities that can be planned in advance and conducted systematically. The
underlying motivation of program testing is to affirm software quality with methods that
can economically and effectively apply to both strategic to both large and small-scale
systems.
Data Collection
The dataset used in the experiments was extracted from CelebA [24]. The images
from the CelebA covered large pose variations and background clutter, including 10,177 of
identities and 202,599 aligned face images. In the experiment, five state-of-the-art GANs
were used to produce the training set of fake images based on the CelebA dataset, and they
were as follows:
DCGAN (Deep convolutional GAN) [15]
WGAP (Wasserstein GAN) [16]
WGAN-GP (WGAN with Gradient Penalty) [17]
LSGAN (Least Squares GAN) [18]
PGGAN [1]
By using the selected GANs, it was hard to synthesize realistic images with high-
resolution, except for the PGGAN. In [15,16,17,18], the default size of the generated face
images in the released source code was only 64×64 pixels. Specifically, if the size of the
fake image was set to 128×128 pixels, many artifacts would be significant in the generated
images, so the artifacts to recognize the fake image would be easily observed. In such a
case, the fake image detector would not be needed. The most GANs could generate
realistic fake images only of the smaller resolution, such as 64×64 pixels. To achieve a fair
Page | 17
Fraudulent Image Detection
Page | 18
Fraudulent Image Detection
sensor pattern noise [8] for performance comparison. The Baseline-I method was the
jointly learning method based on the contrastive loss and binary cross-entropy loss without
two-step learning. In the Baseline-II method, instead of the CFFN structure, the DenseNet
[19] with two-step learning of the contrastive and binary cross-entropy loss functions was
adopted.
We compared the performance regarding the precision P and recall R, which were
defined as:
P=TPTP+FP
(4)
R=TPTP+FN,
(5)
where TP denoted the number of true positives, indicating that a real image was
recognized as a real, FP denoted the number of false positives, denoting that a fake image
was detected as a real image, and FN denoted the number of false negatives, showing that a
real image was recognized as a fake one.
Objective Performance Comparison
To verify the effectiveness of the proposed method, we excluded one of the selected
GANs from the training process and used it in the testing process instead to make the
training and test sets be different. For instance, when the PGGAN was excluded from the
training phase of the proposed DeepFD, the fake images generated by the PGGAN and the
corresponding real images were used to evaluate the performance of the trained fake face
detector. The objective performance comparison of the proposed fake face detector, two
baseline methods, and methods proposed in [9,10,11] in terms of precision and recall, is
presented in Table 3. As presented in Table 3, the proposed method significantly
outperformed other state-of-the-art methods; thus, the CFFN can be used to capture the
discriminative features of the fake images. The curves of the validation accuracy during the
training phase are depicted in Figure 4. It demonstrated that the effectiveness of the
proposed DeepFD. The proposed pairwise learning successfully captured the CFFs from
Page | 19
Fraudulent Image Detection
the training images generated by different GANs. Thus, it was verified that the proposed
method had higher generalization ability and effectiveness than the other methods.
The curves of the validation accuracy during the training phase for the proposed DeepFD.
The objective performance comparison of the proposed and other fake face detectors.
Visualized Result
As presented in [26], the object can be localized by designing the number of channels
in the last convolution layers to be the same as the number of classes. Also, as suggested in
[26], the channels of the last convolutional layer of the proposed CDNN enable the
visualization ability. Therefore, the proposed model was used to visualize fake regions in
the generated images by extracting the last convolution layer and mapping the responses to
the image domain. Since the last convolution layer was designed to have two channels, the
first channel was regarded as a feature response of the first class (i.e., real image), and the
Page | 20
Fraudulent Image Detection
second channel corresponded to the second class (i.e., fake image). As a result, the
proposed method could be used to visualize the fake regions, making a more intuitive
interpretation of typical fake features generated by the GANs. Moreover, the heat map of
the last convolutional layer is produced by the normalized response values in the feature
map with the second channel (i.e., the feature map for fake feature). As a result in Figure
5, the higher feature response values can be observed in the corresponding regions with
artifacts in the fake face images, while the real images have relatively lower feature
response values. We map the response value to the original image to draw the artifact
regions in red color.
The visualized fake feature map for localization of fake regions in face images generated
by the (a–e) WGAN [16] and (f–j) PGGAN [1]. (k–t) are the real images and the
corresponding feature responses.
Training Convergence
In the proposed method, it is necessary to guarantee the convergence of network
training. Therefore, the convergence of the contrastive loss and CFFN training accuracy
was analyzed, and the results are presented in Figure 6. In Figure 6a, the orange line
depicts the accuracy curve during the training with supervised learning without contrastive
loss, and the blue line indicates the validation accuracy curve of the training process with
the proposed pairwise learning in two-step learning policy. It is clear that the proposed
Page | 21
Fraudulent Image Detection
Figure 6. (a) The curves of the validation accuracy evaluated on the fake face images
generated by PGGAN during the training phase for the proposed DeepFD, Baseline-I, and
Baseline-II. (b) The curves of the contrastive loss values of the proposed DeepFD (in Log-
view).
In general, over-fitting can be observed when the validation accuracy is dropping
down as well as the training accuracy is still improving. In our experiments, the validation
accuracy only slightly improves after 21,000 iterations. It is clear that the validation
accuracy in Figure 6a does not drop down after 21,000 iterations. Therefore, the total
number of the training iterations can be higher than 21,000.
Fake General Image Detection
In the task of fake general image detection, we used three state-of-the-art GANs to
generate high-quality fake images:
BigGAN (Large Scale GAN Training for High Fidelity Natural Image Synthesis)
[2]
SA-GAN (Self-Attention GAN) [27]
SN-GAN (Spectral Normalization GAN) [28]
Page | 22
Fraudulent Image Detection
The dataset was extracted from the ILSVRC12 [29]. We adopted the source code
provided in [2,27,28] and its released model that was trained on the ILSVRC12 to generate
the fake general images. Each GAN generated 100,000 fake images with a size
of 128×128, which were recorded into the fake general image pool. Then, we randomly
selected 300,000 real images from the ILSVRC12. Therefore, the total number of images
was 600,000. To evaluate the performance of the proposed method, we split the image
dataset into the training, validation, and test sets that consisted of 580,000, 10,000,
and 10,000 images, respectively.
The objective performance comparison of the proposed method and other state-of-the-
art image forgery detection methods is presented in Table 4. The results given in Table
4 show that the proposed CFFN with the pairwise learning strategy was significantly better
than other state-of-the-art image forgery detectors. Compared to the supervised learning-
based methods [9,11], the performance of the proposed method was significantly better.
Accordingly, it was proven that the proposed method could learn the CFF of a fake general
image.The subjective performance comparison of the proposed and other fake general
image detectors.
Discussions and Limitations
In the proposed CFFN and DeepFD, the fake face and general image detection ability
is provided using deep neural networks. Since the main contribution of this work is that the
CFFs are learned from the pairwise training samples, the proposed CFFs may fail when the
fake features of the results of a new generator are significantly different from most of those
used in the training phase. In such a situation, the fake face and general image detector
should be retrained. Another limitation of the proposed method is related to the collection
of training samples. The technical details of some fake image generators maybe have not
been revealed, so the training samples might be hard to collect in practice. In order to
overcome this limitation, a few-shot learning policy should be employed in the learning of
the CFF from a small-scale training set.
Page | 23
Fraudulent Image Detection
TYPES OF TESTING
There are different types of testing used in the project. They are following
• Unit Testing
• Integration Testing
A strategy for software testing may also be viewed in the context of the spiral. Unit testing
begins at the vertex of the spiral and concentrates on each unit of the software as
implemented in source code. Testing progress by moving outward along the spiral to
integration testing, where the focus is on the design and the construction of the software
architecture.
Talking another t urn on outward on the spiral we encounter validation testing where
requirements established as part of software requirements analysis are validated against the
software that has been constructed. Finally we arrive at system testing, where the software
and other system elements are tested as a whole.
Unit testing is the testing of an individual unit or group of related units. If falls under the
class of white box testing. It is often done by the programmer to test that the unit he/she
has implemented is producing expected output against given input. Unit testing is a
software development process that involves synchronized application of a broad spectrum
Page | 24
Fraudulent Image Detection
of defect prevention and detection strategies in order to reduce software development risks,
time, and costs.
It is performed by the software developer or engineer during the construction phase of the
software development lifecycle. Rather than replace traditional QA focuses, it augments it.
Unit testing aims to eliminate construction errors before code is promoted to QA.
White box testing is a testing technique that takes into account the internal mechanism of a
system. It is also called structural testing and glass box testing. White-box testing can be
applied at the unit, integration and system levels of the software testing process, it is
usually done at the unit level.
It can test paths within a unit, paths between units during integration, and between
subsystems during a system-level test. Though this method of test design can uncover
many errors or problems, it might not detect unimplemented parts of the specification or
missing requirements. Techniques used in white-box testing include:
• API testing
• Code coverage
• Fault injection
Page | 25
Fraudulent Image Detection
Black –box testing treats the software as a “black box”, examining functionality without
any knowledge of internal implementation. Black-box testing methods include:
equivalence partitioning, boundary value analysis, all-pairs testing, state transition tables,
decision table testing, fuzz testing, model-based testing, use case testing, exploratory
testing and specification based testing.
One advantages of the black box technique is that no programming knowledge is required.
On the other hand, black –box testing has been said to be “like a walk in a dark labyrinth
without a flashlight. This method of test can be applied to all levels of software testing:
unit, integration, system and acceptance.
9.6.1 Conclusion
Neural network has been successfully trained using the error level analysis
with 4000 fake and 4000 real images. The trained neural network was able to recognize the
image as fake or real at a maximum success rate of 83%. The use of this application in
mobile platforms will greatly reduce the spreading of fake images through social media.
This project can also be used as a false proof technique in digital authentication, court
evidence evaluation etc. By combining the results of metadata analysis (40%) and neural
network output (60%) a reliable fake image detection program is developed and tested.
Page | 26
Fraudulent Image Detection
10. Results
10.1 Coding:
ConstantObjects.class:
package com.gc.fakeimagedetection.core;
import com.gc.fakeimagedetection.core.errorlevelanalysis.FIDErrorLevelAnalysis;
import com.gc.fakeimagedetection.core.listener.ErrorLevelAnalysisListener;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.HashMap;
import org.neuroph.core.NeuralNetwork;
import org.neuroph.imgrec.ImageRecognitionPlugin;
Page | 27
Fraudulent Image Detection
new FIDNetworkAnalyser(neuralSource)
.run(imageLoc, Integer.parseInt(quality),
new Dimension(Integer.parseInt(sWidth),
Integer.parseInt(sHeight)));
Page | 28
Fraudulent Image Detection
@Override
public void elaCompleted(BufferedImage image) {
if(image==null)
return;
processOnNeuralNetwork(image);
}
}
FIDNetworkTrainer.java
package com.gc.fakeimagedetection.core;
import com.gc.fakeimagedetection.core.listener.BatchImageTrainingListener;
import com.gc.fakeimagedetection.core.trainer.BatchImageTrainer;
import java.awt.Dimension;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
Page | 29
Fraudulent Image Detection
@Override
public void batchImageTrainingCompleted() {
System.out.println("Training Completed");
}
@Override
Page | 30
Fraudulent Image Detection
}
FIDPreprocessor.java
package com.gc.fakeimagedetection.core;
import com.gc.fakeimagedetection.core.errorlevelanalysis.ImageStandardizer;
import java.awt.Dimension;
import java.io.File;
Page | 31
Fraudulent Image Detection
ImageStandardizer preprocessor
= new ImageStandardizer(new File(srcDir), new File(destDir),
new Dimension(Integer.parseInt(sWidth), Integer.parseInt(sHeight)),
outLabel);
}
}
ConstantObjects.java:
package com.gc.fakeimagedetection.core.constants;
Page | 32
Fraudulent Image Detection
import com.gc.fakeimagedetection.core.listener.ErrorLevelAnalysisUpdateListener;
import com.gc.fakeimagedetection.ui.alert.Calert;
import com.gc.fakeimagedetection.core.multithread.NotifyingThread;
import ij.ImagePlus;
import ij.io.FileSaver;
import static ij.io.FileSaver.setJpegQuality;
import ij.plugin.ContrastEnhancer;
import ij.plugin.ImageCalculator;
import ij.process.ImageProcessor;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Rectangle;
import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import javafx.scene.control.Alert;
import javax.imageio.ImageIO;
Page | 33
Fraudulent Image Detection
String fileLocation;
String destination = "output/processed";
int quality = 95;
Boolean runningStatus = false;
Dimension sampledDimension;
String outLabel;
ArrayList<String> supportedExtensions;
ErrorLevelAnalysisUpdateListener listener;
int baseCount = 1;
Page | 34
Fraudulent Image Detection
this.outLabel = outLabel;
}
@Override
public void doRun() {
try {
System.out.println("Changing Images to size " + sampledDimension);
Page | 35
Fraudulent Image Detection
runningStatus = true;
Image img;
try {
img = ImageIO.read(file);
} catch (IOException ex) {
System.err.println("Null Image");
return;
}
ImagePlus orig = new ImagePlus("Source Image", img);
if (orig.getWidth() < sampledDimension.getWidth() || orig.getHeight() <
sampledDimension.getHeight()) {
System.err.println("Too Small to process");
continue;
}
setJpegQuality(quality);
fs.saveAsJpeg(resavedPath);
ImagePlus resaved = new ImagePlus(resavedPath);
Page | 36
Fraudulent Image Detection
ImageProcessor ip = diff.getProcessor();
ImageProcessor imp;
if (ip.getWidth() > ip.getHeight()) {
Rectangle rec = new Rectangle(0, 0, ip.getHeight(), ip.getHeight());
ip.setRoi(rec);
imp = ip.crop();
} else {
Rectangle rec = new Rectangle(0, 0, ip.getWidth(), ip.getWidth());
ip.setRoi(rec);
imp = ip.crop();
}
imp = imp.resize((int) sampledDimension.getWidth(), (int)
sampledDimension.getHeight());
FileSaver resultSaver = new FileSaver(new ImagePlus("Result",
Page | 37
Fraudulent Image Detection
imp.getBufferedImage()));
runningStatus = false;
}
} catch (Exception e) {
System.err.println("Error Occured at Ela_processor :" + e.getMessage());
}
}
Page | 38
Fraudulent Image Detection
} else {
break;
}
}
System.out.println("There are " + (baseCount - 1) + " images already. Starting
from " + baseCount);
}
}
FIDErrorLevelAnalysis.java
package com.gc.fakeimagedetection.core.errorlevelanalysis;
import com.gc.fakeimagedetection.core.listener.ErrorLevelAnalysisListener;
import com.gc.fakeimagedetection.core.multithread.NotifyingThread;
import com.gc.fakeimagedetection.ui.alert.Calert;
import ij.ImagePlus;
import ij.io.FileSaver;
import static ij.io.FileSaver.setJpegQuality;
import ij.plugin.ContrastEnhancer;
import ij.plugin.ImageCalculator;
import ij.process.ImageProcessor;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Rectangle;
import java.io.File;
import java.io.IOException;
import javafx.application.Platform;
import javafx.scene.control.Alert;
Page | 39
Fraudulent Image Detection
import javax.imageio.ImageIO;
String fileLocation;
int quality = 95;
Boolean runningStatus = false;
Dimension sampledDimension;
ErrorLevelAnalysisListener listener;
@Override
public void doRun() {
try {
Image img;
try {
System.out.println("Loading Image :" + fileLocation);
img = ImageIO.read(new File(fileLocation));
} catch (IOException ex) {
System.err.println("Null Image");
Page | 40
Fraudulent Image Detection
return;
}
System.out.println("Dimension is set to " + sampledDimension);
ImagePlus orig = new ImagePlus("Source Image", img);
setJpegQuality(quality);
fs.saveAsJpeg(resavedPath);
ImagePlus resaved = new ImagePlus(resavedPath);
Page | 41
Fraudulent Image Detection
ImageProcessor ip = diff.getProcessor();
ImageProcessor imp;
if (ip.getWidth() > ip.getHeight()) {
Rectangle rec = new Rectangle(0, 0, ip.getHeight(), ip.getHeight());
ip.setRoi(rec);
imp = ip.crop();
} else {
Rectangle rec = new Rectangle(0, 0, ip.getWidth(), ip.getWidth());
ip.setRoi(rec);
imp = ip.crop();
}
Page | 42
Fraudulent Image Detection
}
ImageStandardizer.java:
package com.gc.fakeimagedetection.core.errorlevelanalysis;
import com.gc.fakeimagedetection.core.listener.ErrorLevelAnalysisUpdateListener;
import com.gc.fakeimagedetection.core.constants.ConstantObjects;
import com.gc.fakeimagedetection.core.listener.ThreadCompleteListener;
import java.awt.Dimension;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
Page | 43
Fraudulent Image Detection
resolution = finalResolution;
destDir = destinationDirectory;
outputLabel = outLabel;
}
void init() {
supportedExtensions = new
ArrayList<>(Arrays.asList(ConstantObjects.supportedExtensions));
}
Page | 44
Fraudulent Image Detection
imageProcessor.start();
}
@Override
public void notifyOfThreadComplete(Thread thread) {
System.out.println("Image Processing Completed");
System.exit(0);
}
}
Batchimageprocessor.fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXButton?>
Page | 45
Fraudulent Image Detection
<?import com.jfoenix.controls.JFXCheckBox?>
<?import com.jfoenix.controls.JFXTextField?>
<?import javafx.scene.control.ProgressBar?>
<?import javafx.scene.effect.DropShadow?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Text?>
Page | 46
Fraudulent Image Detection
.gitignore.gf
__pycache__/
.vscode/*
Page | 47
Fraudulent Image Detection
static/uploaded_videos/*.mp4
static/cartoonized_images/*.jpg
config.yaml
run_local: true #Set this to true if you are running locally, false if you have configured the
Google buckets and algorithmia code.
gpu: true #Set this to true if you want to use the GPU
trim-video: true #Set this to false if you want to process full video
trim-video-length: 15 #Max number of seconds you want to trim the video from start
original_frame_rate: false #If False output_frame_rate will be used else original video
detected frame rate will be used, if no metadata found will use output_frame_rate
original_resolution: false # Set to true if you don't want to resize the original video
resize-dim: 720 #The width of the video will be resized to specified number maintaining
aspect ratio
FIDNetworkTrainer.java
package com.gc.fakeimagedetection.core;
import com.gc.fakeimagedetection.core.listener.BatchImageTrainingListener;
Page | 48
Fraudulent Image Detection
import com.gc.fakeimagedetection.core.trainer.BatchImageTrainer;
import java.awt.Dimension;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
return;
Page | 49
Fraudulent Image Detection
@Override
System.out.println("Training Completed");
@Override
Page | 50
Fraudulent Image Detection
private void run(String sourceDir, String neuralDir, String sWidth, String sHeight,
String imageLabelString) {
labels.addAll(Arrays.asList(imageLabelString.split(",")));
BatchImageTrainer neuralTrainer
neuralTrainer.setMaxError(MERROR);
neuralTrainer.setMomentum(MOMENTUM);
neuralTrainer.setLearningRate(LEARNING_RATE);
neuralTrainer.start();
MLPNetworkMaker.java
package com.gc.fakeimagedetection.core.neuralnet;
Page | 51
Fraudulent Image Detection
import com.gc.fakeimagedetection.core.listener.NeuralNetworkCreationCompleteListener;
import java.util.List;
import org.neuroph.core.NeuralNetwork;
import org.neuroph.imgrec.ColorMode;
import org.neuroph.imgrec.ImageRecognitionHelper;
import org.neuroph.imgrec.image.Dimension;
import org.neuroph.util.TransferFunctionType;
String networkLabel;
Dimension samplingDimension;
ColorMode mode;
List<String> outputNeuronLabels;
List<Integer> neuronCounts;
TransferFunctionType type;
NeuralNetwork nnet;
Page | 52
Fraudulent Image Detection
String saveLocation;
NeuralNetworkCreationCompleteListener listener;
this.listener = listener;
this.networkLabel = networkLabel;
this.samplingDimension = samplingDimension;
this.mode = mode;
this.outputNeuronLabels = outputNeuronLabels;
this.neuronCounts = neuronCounts;
this.type = type;
this.saveLocation = saveLocation;
Page | 53
Fraudulent Image Detection
@Override
try {
nnet = ImageRecognitionHelper.createNewNeuralNetwork(networkLabel,
samplingDimension, mode, outputNeuronLabels, neuronCounts, type);
if (nnet == null) {
nnet.save(saveLocation);
} catch (Exception e) {
flag = false;
listener.networkCreationComplete(flag);
NeuralNetProcessor.java
package com.gc.fakeimagedetection.core.processor;
Page | 54
Fraudulent Image Detection
import com.gc.fakeimagedetection.core.constants.ConstantObjects;
import com.gc.fakeimagedetection.core.listener.NeuralnetProcessorListener;
import com.gc.fakeimagedetection.core.multithread.NotifyingThread;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Platform;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javax.imageio.ImageIO;
import org.neuroph.core.NeuralNetwork;
import org.neuroph.imgrec.ImageRecognitionPlugin;
Page | 55
Fraudulent Image Detection
NeuralnetProcessorListener listener;
this.listener = listener;
try {
System.out.println("Loading Image....");
Page | 56
Fraudulent Image Detection
System.out.println("Loading NN....");
if (!NNetwork.exists()) {
return;
imageRecognition = (ImageRecognitionPlugin)
nnet.getPlugin(ImageRecognitionPlugin.class); // get the image recognition plugin from
neural network
System.out.println("Recognize Image....");
System.out.println("Output is....");
System.out.println(output.toString());
Logger.getLogger(NeuralNetProcessor.class.getName()).log(Level.SEVERE, null,
ex);
}
Page | 57
Fraudulent Image Detection
this.image = image;
void notifyUser() {
Platform.runLater(new Runnable() {
@Override
alert.showAndWait();
});
Page | 58
Fraudulent Image Detection
@Override
try {
if (nnet == null) {
if (!NNetwork.exists()) {
notifyUser();
return;
imageRecognition = (ImageRecognitionPlugin)
nnet.getPlugin(ImageRecognitionPlugin.class); // get the image recognition plugin from
neural network
Page | 59
Fraudulent Image Detection
if (output == null) {
System.out.println(output.toString());
listener.neuralnetProcessCompleted(output);
Logger.getLogger(NeuralNetProcessor.class.getName()).log(Level.SEVERE, null,
ex);
listener.neuralnetProcessCompleted(null);
requirements.txt
Flask==1.0.2
gunicorn==20.0.4
Pillow==6.2.0
Page | 60
Fraudulent Image Detection
opencv_python==4.2.0.34
tensorflow==2.1.0
google-cloud-storage==1.29.0
algorithmia==1.3.0
scikit-video==1.1.11
tf_slim==1.1.0
PyYaml==5.3.1
flask-ngrok
Page | 61
Fraudulent Image Detection
Page | 62
Fraudulent Image Detection
Page | 63
Fraudulent Image Detection
Page | 64
Fraudulent Image Detection
10.2.4 Result:
Page | 65
Fraudulent Image Detection
Page | 66
Fraudulent Image Detection
10.2.61 Result:
Page | 67
Fraudulent Image Detection
11. References
Book Reference
Web Reference
[1] A picture‟s worth, Digital Image Analysis and Forensics, N Krawetz - 2007 Ph
D, Hacker Factor Solutions
[2] http://imagej.net/Welcome ImageJ is an open source image processing program
designed for scientific multidimensional images.J. Clerk Maxwell, A Treatise on
Electricity and Magnetism, 3rd ed., vol. 2. Oxford: Clarendon, 1892, pp.68–73.
[3] http://forensics.idealtest.org/ CASIA v2.0 CASIA V2.0 is with larger size and
with more realistic and challenged fake images by using post-processing of tampered
regions. It contains 7491 authentic and 5123 tampered color images.
[4] http://neuroph.sourceforge.net/ Neuroph Framework Neuroph is lightweight
Java neural network framework to develop common neural network architectures. It
contains well designed, open source Java library with small number of basic classes which
correspond to basic NN concepts.
Page | 68
Fraudulent Image Detection
Page | 69