CRUD
------------------------------------------------------------------------------------------------------------
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.Mk.bean;
import com.Mk.dao.customerDao;
import com.Mk.daoImpl.customerDaoImpl;
import com.Mk.entity.Customer;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import org.primefaces.event.RowEditEvent;
import org.primefaces.model.LazyDataModel;
@ManagedBean(name = "customer")
@SessionScoped
public class customerBean {
private String customerName;
private String customerEmail;
private String customerPhoneNo;
private String customerAddress;
private String customerCity;
private String customerPincode;
private String customerState;
private String customerCountry;
private String customerWebsite;
private String customerComments;
private Customer selectedcust;
public Customer getSelectedcust() {
return selectedcust;
}
public void setSelectedcust(Customer selectedcust) {
this.selectedcust = selectedcust;
}
public String getCustomerAddress() {
return customerAddress;
}
public void setCustomerAddress(String customerAddress) {
this.customerAddress = customerAddress;
}
public String getCustomerCity() {
return customerCity;
}
public void setCustomerCity(String customerCity) {
this.customerCity = customerCity;
}
public String getCustomerPincode() {
return customerPincode;
}
public void setCustomerPincode(String customerPincode) {
this.customerPincode = customerPincode;
}
public String getCustomerState() {
return customerState;
}
public void setCustomerState(String customerState) {
this.customerState = customerState;
}
public String getCustomerCountry() {
return customerCountry;
}
public void setCustomerCountry(String customerCountry) {
this.customerCountry = customerCountry;
}
public String getCustomerWebsite() {
return customerWebsite;
}
public void setCustomerWebsite(String customerWebsite) {
this.customerWebsite = customerWebsite;
}
public String getCustomerComments() {
return customerComments;
}
public void setCustomerComments(String customerComments) {
this.customerComments = customerComments;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getCustomerEmail() {
return customerEmail;
}
public void setCustomerEmail(String customerEmail) {
this.customerEmail = customerEmail;
}
public String getCustomerPhoneNo() {
return customerPhoneNo;
}
public void setCustomerPhoneNo(String customerPhoneNo) {
this.customerPhoneNo = customerPhoneNo;
}
private void addMessage(FacesMessage message) {
FacesContext.getCurrentInstance().addMessage(null, message);
}
public void addCustomer() {
customerDao dao=new customerDaoImpl();
Customer cust=new Customer();
cust.setCustomerName(customerName);
cust.setCustomerEmail(customerEmail);
cust.setCustomerPhoneNo(customerPhoneNo);
cust.setCustomerAddress(customerAddress);
cust.setCustomerCity(customerCity);
cust.setCustomerComments(customerComments);
cust.setCustomerPincode(customerPincode);
cust.setCustomerWebsite(customerWebsite);
cust.setCustomerCountry(customerCountry);
cust.setCustomerState(customerState);
dao.insertCustomer(cust);
addMessage(new FacesMessage(FacesMessage.SEVERITY_INFO, customerName
+ " Details Was Saved Successfully!!!", null));
}
public void resetCustomer() {
this.customerName=null;
this.customerEmail=null;
this.customerPhoneNo=null;
this.customerAddress=null;
this.customerCity=null;
this.customerComments=null;
this.customerPincode=null;
this.customerWebsite=null;
this.customerCountry=null;
this.customerState=null;
}
private List<Customer> allCustomer;
public List<Customer> findAll() {
allCustomer=new ArrayList<Customer>();
customerDao dao=new customerDaoImpl();
allCustomer=dao.viewCustomer();
return allCustomer;
}
public void editCustomer(RowEditEvent event) {
customerDao dao=new customerDaoImpl();
dao.editCustomer((Customer) event.getObject());
}
@SuppressWarnings("empty-statement")
public void onEdit(RowEditEvent event) {
FacesMessage msg = new FacesMessage("Customer Edited", ((Customer) event.getObject()).getCustomerName());
customerDao dao=new customerDaoImpl();
dao.editCustomer((Customer) event.getObject());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void onCancel(RowEditEvent event) {
FacesMessage msg = new FacesMessage("Customer Cancelled", ((Customer) event.getObject()).getCustomerName());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public List<Customer> remove(Customer c) {
customerDao dao=new customerDaoImpl();
dao.removeCustomer(c);
allCustomer=dao.viewCustomer();
return allCustomer;
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.Mk.bean;
import com.Mk.dao.customerDao;
import com.Mk.daoImpl.customerDaoImpl;
import com.Mk.entity.Customer;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import org.primefaces.event.RowEditEvent;
import org.primefaces.model.LazyDataModel;
@ManagedBean(name = "customer")
@SessionScoped
public class customerBean {
private String customerName;
private String customerEmail;
private String customerPhoneNo;
private String customerAddress;
private String customerCity;
private String customerPincode;
private String customerState;
private String customerCountry;
private String customerWebsite;
private String customerComments;
private Customer selectedcust;
public Customer getSelectedcust() {
return selectedcust;
}
public void setSelectedcust(Customer selectedcust) {
this.selectedcust = selectedcust;
}
public String getCustomerAddress() {
return customerAddress;
}
public void setCustomerAddress(String customerAddress) {
this.customerAddress = customerAddress;
}
public String getCustomerCity() {
return customerCity;
}
public void setCustomerCity(String customerCity) {
this.customerCity = customerCity;
}
public String getCustomerPincode() {
return customerPincode;
}
public void setCustomerPincode(String customerPincode) {
this.customerPincode = customerPincode;
}
public String getCustomerState() {
return customerState;
}
public void setCustomerState(String customerState) {
this.customerState = customerState;
}
public String getCustomerCountry() {
return customerCountry;
}
public void setCustomerCountry(String customerCountry) {
this.customerCountry = customerCountry;
}
public String getCustomerWebsite() {
return customerWebsite;
}
public void setCustomerWebsite(String customerWebsite) {
this.customerWebsite = customerWebsite;
}
public String getCustomerComments() {
return customerComments;
}
public void setCustomerComments(String customerComments) {
this.customerComments = customerComments;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getCustomerEmail() {
return customerEmail;
}
public void setCustomerEmail(String customerEmail) {
this.customerEmail = customerEmail;
}
public String getCustomerPhoneNo() {
return customerPhoneNo;
}
public void setCustomerPhoneNo(String customerPhoneNo) {
this.customerPhoneNo = customerPhoneNo;
}
private void addMessage(FacesMessage message) {
FacesContext.getCurrentInstance().addMessage(null, message);
}
public void addCustomer() {
customerDao dao=new customerDaoImpl();
Customer cust=new Customer();
cust.setCustomerName(customerName);
cust.setCustomerEmail(customerEmail);
cust.setCustomerPhoneNo(customerPhoneNo);
cust.setCustomerAddress(customerAddress);
cust.setCustomerCity(customerCity);
cust.setCustomerComments(customerComments);
cust.setCustomerPincode(customerPincode);
cust.setCustomerWebsite(customerWebsite);
cust.setCustomerCountry(customerCountry);
cust.setCustomerState(customerState);
dao.insertCustomer(cust);
addMessage(new FacesMessage(FacesMessage.SEVERITY_INFO, customerName
+ " Details Was Saved Successfully!!!", null));
}
public void resetCustomer() {
this.customerName=null;
this.customerEmail=null;
this.customerPhoneNo=null;
this.customerAddress=null;
this.customerCity=null;
this.customerComments=null;
this.customerPincode=null;
this.customerWebsite=null;
this.customerCountry=null;
this.customerState=null;
}
private List<Customer> allCustomer;
public List<Customer> findAll() {
allCustomer=new ArrayList<Customer>();
customerDao dao=new customerDaoImpl();
allCustomer=dao.viewCustomer();
return allCustomer;
}
public void editCustomer(RowEditEvent event) {
customerDao dao=new customerDaoImpl();
dao.editCustomer((Customer) event.getObject());
}
@SuppressWarnings("empty-statement")
public void onEdit(RowEditEvent event) {
FacesMessage msg = new FacesMessage("Customer Edited", ((Customer) event.getObject()).getCustomerName());
customerDao dao=new customerDaoImpl();
dao.editCustomer((Customer) event.getObject());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void onCancel(RowEditEvent event) {
FacesMessage msg = new FacesMessage("Customer Cancelled", ((Customer) event.getObject()).getCustomerName());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public List<Customer> remove(Customer c) {
customerDao dao=new customerDaoImpl();
dao.removeCustomer(c);
allCustomer=dao.viewCustomer();
return allCustomer;
}
}
------------------------------------------------------------------------------------------------------------
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.Mk.bean;
import java.io.IOException;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;
/**
*
* @author manoj
*/
@ManagedBean(name = "login")
@SessionScoped
public class loginbean {
String username;
String Password;
//<f:event listener="#{login.sessiontest(login.username)}" type="preRenderView" />
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return Password;
}
public void setPassword(String Password) {
this.Password = Password;
}
public String validate()
{
FacesContext fc = FacesContext.getCurrentInstance();
String user = (String) fc.getExternalContext().getSessionMap().put("user", username);
if ("admin".equals(username) && "admin".equals(Password))
{
return "/faces/registration?faces-redirect=true";
}
if (!"admin".equals(username) || !"admin".equals(Password))
{ show();}
return null;
}
public void show()
{
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage("Login failed","Invalid Details"));
}
public String sessiontest() throws IOException
{
FacesContext fc = FacesContext.getCurrentInstance();
String user = (String) fc.getExternalContext().getSessionMap().get("user");
if (user==null)
{
redirect("login.xhtml");
}
return null;
}
private void redirect(String url) throws IOException {
FacesContext fc = FacesContext.getCurrentInstance();
fc.getExternalContext().redirect(url);
}
public String logout()
{
((HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true)).invalidate();
return "/faces/login?faces-redirect=true";
}
}
------------------------------------------------------------------------------------------------------------
DAO
------------------------------------------------------------------------------------------------------------
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.Mk.dao;
import com.Mk.entity.Customer;
import java.util.List;
public interface customerDao {
public void insertCustomer(Customer cust);
public List<Customer> viewCustomer();
public void editCustomer(Customer cust);
public List<Customer> removeCustomer(Customer cust);
}
------------------------------------------------------------------------------------------------------------
DAO impl
------------------------------------------------------------------------------------------------------------
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.Mk.daoImpl;
import com.Mk.dao.customerDao;
import com.Mk.entity.Customer;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.context.FacesContext;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class customerDaoImpl implements customerDao {
@Override
public void insertCustomer(Customer cust) {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("SampleCrudJSFPU");
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
try {
em.persist(cust);
em.getTransaction().commit();
}
catch (Exception e) {
e.printStackTrace();
em.getTransaction().rollback();
} finally {
em.close();
}
}
@Override
public List<Customer> viewCustomer() {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("SampleCrudJSFPU");
EntityManager em = emf.createEntityManager();
List<Customer> allCustomer=null;
try {
em.getTransaction().begin();
allCustomer = em.createNamedQuery("Customer.findAll").getResultList();
em.getTransaction().commit();
} catch (Exception e) {
e.printStackTrace();
em.getTransaction().rollback();
} finally {
em.close();
}
return allCustomer;
}
@Override
public void editCustomer(Customer cust) {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("SampleCrudJSFPU");
EntityManager em = emf.createEntityManager();
try {
em.getTransaction().begin();
em.merge(cust);
em.getTransaction().commit();
} catch (Exception e) {
e.printStackTrace();
em.getTransaction().rollback();
} finally {
em.close();
}
}
@Override
public List<Customer> removeCustomer(Customer cust) {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("SampleCrudJSFPU");
EntityManager em = emf.createEntityManager();
List<Customer> allCustomer=null;
try {
em.getTransaction().begin();
em.remove(em.find(Customer.class, cust.getCustomerid()));
em.flush();
em.getTransaction().commit();
}
catch (Exception e) {
e.printStackTrace();
em.clear();
em.close();
}
return allCustomer;
}
}
------------------------------------------------------------------------------------------------------------
entity
------------------------------------------------------------------------------------------------------------
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.Mk.entity;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
* @author manoj
*/
@Entity
@Table(name = "customer")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Customer.findAll", query = "SELECT c FROM Customer c"),
@NamedQuery(name = "Customer.findByCustomerid", query = "SELECT c FROM Customer c WHERE c.customerid = :customerid"),
@NamedQuery(name = "Customer.findByCustomerEmail", query = "SELECT c FROM Customer c WHERE c.customerEmail = :customerEmail"),
@NamedQuery(name = "Customer.findByCustomerName", query = "SELECT c FROM Customer c WHERE c.customerName = :customerName"),
@NamedQuery(name = "Customer.findByCustomerPhoneNo", query = "SELECT c FROM Customer c WHERE c.customerPhoneNo = :customerPhoneNo"),
@NamedQuery(name = "Customer.findByCustomerAddress", query = "SELECT c FROM Customer c WHERE c.customerAddress = :customerAddress"),
@NamedQuery(name = "Customer.findByCustomerCity", query = "SELECT c FROM Customer c WHERE c.customerCity = :customerCity"),
@NamedQuery(name = "Customer.findByCustomerPincode", query = "SELECT c FROM Customer c WHERE c.customerPincode = :customerPincode"),
@NamedQuery(name = "Customer.findByCustomerState", query = "SELECT c FROM Customer c WHERE c.customerState = :customerState"),
@NamedQuery(name = "Customer.findByCustomerCountry", query = "SELECT c FROM Customer c WHERE c.customerCountry = :customerCountry"),
@NamedQuery(name = "Customer.findByCustomerWebsite", query = "SELECT c FROM Customer c WHERE c.customerWebsite = :customerWebsite"),
@NamedQuery(name = "Customer.findByCustomerComments", query = "SELECT c FROM Customer c WHERE c.customerComments = :customerComments")})
public class Customer implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "Customer_id")
private Integer customerid;
@Column(name = "customerEmail")
private String customerEmail;
@Column(name = "customerName")
private String customerName;
@Column(name = "customerPhoneNo")
private String customerPhoneNo;
@Column(name = "customerAddress")
private String customerAddress;
@Column(name = "customerCity")
private String customerCity;
@Column(name = "customerPincode")
private String customerPincode;
@Column(name = "customerState")
private String customerState;
@Column(name = "customerCountry")
private String customerCountry;
@Column(name = "customerWebsite")
private String customerWebsite;
@Column(name = "customerComments")
private String customerComments;
public Customer() {
}
public Customer(Integer customerid) {
this.customerid = customerid;
}
public Integer getCustomerid() {
return customerid;
}
public void setCustomerid(Integer customerid) {
this.customerid = customerid;
}
public String getCustomerEmail() {
return customerEmail;
}
public void setCustomerEmail(String customerEmail) {
this.customerEmail = customerEmail;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getCustomerPhoneNo() {
return customerPhoneNo;
}
public void setCustomerPhoneNo(String customerPhoneNo) {
this.customerPhoneNo = customerPhoneNo;
}
public String getCustomerAddress() {
return customerAddress;
}
public void setCustomerAddress(String customerAddress) {
this.customerAddress = customerAddress;
}
public String getCustomerCity() {
return customerCity;
}
public void setCustomerCity(String customerCity) {
this.customerCity = customerCity;
}
public String getCustomerPincode() {
return customerPincode;
}
public void setCustomerPincode(String customerPincode) {
this.customerPincode = customerPincode;
}
public String getCustomerState() {
return customerState;
}
public void setCustomerState(String customerState) {
this.customerState = customerState;
}
public String getCustomerCountry() {
return customerCountry;
}
public void setCustomerCountry(String customerCountry) {
this.customerCountry = customerCountry;
}
public String getCustomerWebsite() {
return customerWebsite;
}
public void setCustomerWebsite(String customerWebsite) {
this.customerWebsite = customerWebsite;
}
public String getCustomerComments() {
return customerComments;
}
public void setCustomerComments(String customerComments) {
this.customerComments = customerComments;
}
@Override
public int hashCode() {
int hash = 0;
hash += (customerid != null ? customerid.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Customer)) {
return false;
}
Customer other = (Customer) object;
if ((this.customerid == null && other.customerid != null) || (this.customerid != null && !this.customerid.equals(other.customerid))) {
return false;
}
return true;
}
@Override
public String toString() {
return "com.Mk.entity.Customer[ customerid=" + customerid + " ]";
}
}
Image comparison using MATLAB (edge detection)
Image comparison using MATLAB
(edge detection)
Here is an simple algorithm for image comparison based on edge detection algorithm.
oq=imread('1.jpg'));
odprz=imresize(oq,[300 300]);
imwrite(odprz,'oq1.jpg');
sw=imread('2.jpg'));
stprz=imresize(sw,[300 300]);
imwrite(stprz,'sw1.png');
pic1 = imread('oq1.jpg');
pic2 = imread('sw1.png');
[x,y,z] = size(pic1);
if(z==1)
;
else
pic1 = rgb2gray(pic1);
end
[x,y,z] = size(pic2);
if(z==1)
;
else
pic2 = rgb2gray(pic2);
end
%applying edge detection on first picture
%so that we obtain white and black points and edges of the objects present
%in the picture.
edge_det_pic1 = edge(pic1,'canny');
%%applying edge detection on second picture
%so that we obtain white and black points and edges of the objects present
%in the picture.
edge_det_pic2 = edge(pic2,'canny');
%definition of different variables to be used in the code below
%initialization of different variables used
matched_data = 0;
matched_data1 = 0;
white_points = 0;
black_points = 0;
x=0;
y=0;
l=0;
m=0;
%for loop used for detecting black and white points in the picture.
for a = 1:1:256
for b = 1:1:256
if(edge_det_pic1(a,b)==1)
white_points = white_points+1;
else
black_points = black_points+1;
end
end
end
%for loop comparing the white (edge points) in the two pictures
for i = 1:1:256
for j = 1:1:256
if(edge_det_pic1(i,j)==1)&(edge_det_pic2(i,j)==1)
matched_data = matched_data+1;
else
matched_data1 = matched_data1+1;
end
end
end
%calculating percentage matching.
total_data = white_points;
total_matched_percentage = (matched_data/total_data)*100;
om=min(odprz);
sm=min(stprz);
if om==255
total_matched_percentage=0;
elseif sm==255
total_matched_percentage=0;
end
disp(total_matched_percentage)
disp('process completed')
No unwanted catch image read error bw nd color
No unwanted catch image read error bw nd color
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URL;
import java.util.ArrayList;
import java.util.Scanner;
import javax.imageio.ImageIO;
public class forjar
{
private static BufferedImage image;
private static BufferedImage image1;
private static final int IMG_WIDTH = 150;
private static final int IMG_HEIGHT = 150;
private static BufferedImage resizeImage(BufferedImage originalImage, int type){
BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
g.dispose();
return resizedImage;
}
public static void main(String[] args) throws IOException
{
Scanner in=new Scanner(System.in);
System.out.println("\n\n\t\t Welcome User\n");
System.out.println("Enter Folder location (e.x) C:\\\\Users\\\\mukunthan.g2\\\\Desktop\\\\New folder\\\\ \n");
//System.out.println("(e.x) C:\\Users\\mukunthan.g2\\Desktop\\New folder\\");
String fi=in.nextLine();
String dataFileName = fi.concat("12.tsv");
BufferedReader bReader = new BufferedReader(new FileReader(dataFileName));
String line;
ArrayList<String> skus = new ArrayList<String>();
ArrayList<String> list = new ArrayList<String>();
ArrayList<String> list1 = new ArrayList<String>();
while ((line = bReader.readLine()) != null)
{
String datavalue[] = line.split("\t");
skus.add(datavalue[0]);
list.add(datavalue[1]);
list1.add(datavalue[2]);
}
bReader.close();
File file = new File(fi.concat("output.txt"));
PrintWriter output = new PrintWriter(file);
ArrayList<String> out1 = new ArrayList<String>();
list1.size();
int k=0;
for (int j=0;j<100;j++)
{
try{
String fu=list1.get(j);
String su=list.get(j);
URL url = new URL(fu);
image = ImageIO.read(url);
ImageIO.write(image, "jpg",new File(fi.concat(("1.jpg"))));
URL url1 = new URL(su);
image = ImageIO.read(url1);
ImageIO.write(image, "jpg",new File(fi.concat("2.jpg")));
for(int i=1;i<=2;i++)
{
if(i==1)
{
BufferedImage originalImage = ImageIO.read(new File(fi.concat("1.jpg")));
int type = originalImage.getType() == 0? BufferedImage.TYPE_INT_RGB : originalImage.getType();
BufferedImage resizeImageJpg = resizeImage(originalImage, type);
ImageIO.write(resizeImageJpg, "jpg", new File(fi.concat("4.jpg")));
}
if(i==2)
{
BufferedImage originalImage = ImageIO.read(new File(fi.concat("2.jpg")));
int type = originalImage.getType() == 0? BufferedImage.TYPE_INT_RGB : originalImage.getType();
BufferedImage resizeImageJpg = resizeImage(originalImage, type);
ImageIO.write(resizeImageJpg, "jpg", new File(fi.concat("5.jpg")));
}
}
//color
BufferedImage biA= ImageIO.read(new File(fi.concat("4.jpg")));
DataBuffer dbA = biA.getData().getDataBuffer();
int sizeA = dbA.getSize();
//color
BufferedImage biB= ImageIO.read(new File(fi.concat("5.jpg")));
DataBuffer dbB = biB.getData().getDataBuffer();
int sizeB = dbB.getSize();
for(int i=1;i<=2;i++)
{
if(i==1)
{
BufferedImage input = ImageIO.read(new File(fi.concat("4.jpg")));
// Create a black-and-white image of the same size.
BufferedImage im =new BufferedImage(150,150,BufferedImage.TYPE_BYTE_BINARY);
// Get the graphics context for the black-and-white image.
Graphics2D g2d = im.createGraphics();
// Render the input image on it.
g2d.drawImage(input,0,0,null);
// Store the resulting image using the PNG format.
ImageIO.write(im,"jpg",new File(fi.concat("44.jpg")));
}
if(i==2)
{
BufferedImage input = ImageIO.read(new File(fi.concat("5.jpg")));
// Create a black-and-white image of the same size.
BufferedImage im =new BufferedImage(150,150,BufferedImage.TYPE_BYTE_BINARY);
// Get the graphics context for the black-and-white image.
Graphics2D g2d = im.createGraphics();
// Render the input image on it.
g2d.drawImage(input,0,0,null);
// Store the resulting image using the PNG format.
ImageIO.write(im,"jpg",new File(fi.concat("55.jpg")));
}}
BufferedImage fbw1= ImageIO.read(new File(fi.concat("44.jpg")));
DataBuffer db_fbw1 = fbw1.getData().getDataBuffer();
int sizeA_fbw1 = db_fbw1.getSize();
BufferedImage sbw1= ImageIO.read(new File(fi.concat("55.jpg")));
DataBuffer db_sbw1 = sbw1.getData().getDataBuffer();
int sizeA_sbw1 = db_sbw1.getSize();
int[] abw=new int[(sizeA_fbw1)];
int[] bbw=new int[(sizeA_fbw1)];
for(int i=0; i<(sizeA_fbw1); i++)
{
abw[i]=db_fbw1.getElem(i); bbw[i]=db_sbw1.getElem(i);
}
int lol=0;
int abw_tot=0; int bbw_tot=0;
for(int i=0; i<(sizeA_fbw1); i++)
{
abw_tot=abw_tot+abw[i]; bbw_tot=bbw_tot+bbw[i];
}
float fst_bw=(abw_tot-bbw_tot);
if(fst_bw<0) fst_bw=fst_bw*(-1);
float finalbw=((fst_bw/abw_tot)*100);
if(finalbw<15)
{
int[] a=new int[16875];
int[] b=new int[16875];
int[] c=new int[16875];
int[] d=new int[16875];
int[] w=new int[16875];
int[] x=new int[16875];
int[] y=new int[16875];
int[] z=new int[16875];
int lo=0;
for(int i=0; i<16875; i++)
{
a[lo]=dbA.getElem(i); w[lo]=dbB.getElem(i);
lo++;
}
lo=0;
for(int i=16875; i<(16874*2); i++)
{
b[lo]=dbA.getElem(i); x[lo]=dbB.getElem(i);
lo++;
}
lo=0;
for(int i=(16874*2); i<(16874*3); i++)
{
c[lo]=dbA.getElem(i); y[lo]=dbB.getElem(i);
lo++;
}
lo=0;
for(int i=(16874*3); i<(16874*4); i++)
{
d[lo]=dbA.getElem(i); z[lo]=dbB.getElem(i);
lo++;
}
float a1=0,b1=0,c1=0,d1=0,w1=0,x1=0,y1=0,z1=0;
for(int i=0; i<16875; i++)
{
a1=a[i]+a1; w1=w[i]+w1;
}
for(int i=0; i<16875; i++)
{
b1=b[i]+b1; x1=x[i]+x1;
}
for(int i=0; i<16875; i++)
{
c1=c[i]+c1; y1=y[i]+y1;
}
for(int i=0; i<16875; i++)
{
d1=d[i]+d1; z1=z[i]+z1;
}
float fst=(a1-w1);
float snd=(b1-x1);
float thd=(c1-y1);
float fth=(d1-z1);
if(fst<0) fst=fst*(-1);
if(snd<0) snd=snd*(-1);
if(thd<0) thd=thd*(-1);
if(fth<0) fth=fth*(-1);
float fst1=(w1-a1);
float snd1=(x1-b1);
float thd1=(y1-c1);
float fth1=(z1-d1);
if(fst1<0) fst1=fst1*(-1);
if(snd1<0) snd1=snd1*(-1);
if(thd1<0) thd1=thd1*(-1);
if(fth1<0) fth1=fth1*(-1);
float oo1=((fst1/a1)*100);
float oo2=((snd1/b1)*100);
float oo3=((thd1/c1)*100);
float oo4=((fth1/d1)*100);
float o1=((fst/a1)*100);
float o2=((snd/b1)*100);
float o3=((thd/c1)*100);
float o4=((fth/d1)*100);
String opt=new String("correct");
String opt1=new String("incorrect");
String result=null;
String skuurl=fu.concat(su);
boolean nasku=skuurl.contains("notavailable");
boolean nasku1=skuurl.contains("genericComingSoon");
boolean nasku2=skuurl.contains("splssku");
if (o1<15 && o2<15 && o3<15 && o4<15 )
{
if (oo1<15 && oo2<15 && oo3<15 && oo4<15 )
{
result=opt;
if(nasku || nasku1 || nasku2)
result="Image_n/a";
System.out.println(result+" "+o1+" "+o2+" "+o3+" "+o4);
}
}
if (o1>15 || o2>15 || o3>15 || o4>15)
{
if (oo1>15 || oo2>15 || oo3>15 || oo4>15)
{
result=opt1;
if(nasku || nasku1 || nasku2)
result="Image_n/a";
System.out.println(result+" "+o1+" "+o2+" "+o3+" "+o4);
}
}
output.println(skus.get(j)+" " +result+" "+o1+" "+o2+" "+o3+" "+o4);
out1.add(result);
k++;
}
if(finalbw>15)
{
System.out.println(finalbw+" "+"incorrect");
output.println(skus.get(j)+" incorrect");
}}
catch (Exception al)
{
System.out.println(skus.get(j)+" image read error");
output.println(skus.get(j)+" image read error");
}
}output.close();}
}
Including b/w & color images for comparison
Including black , white & color images for comparison
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URL;
import java.util.ArrayList;
import java.util.Scanner;
import javax.imageio.ImageIO;
public class own
{
private static BufferedImage image;
private static final int IMG_WIDTH = 150;
private static final int IMG_HEIGHT = 150;
private static BufferedImage resizeImage(BufferedImage originalImage, int type){
BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
g.dispose();
return resizedImage;
}
public static void main(String[] args) throws IOException
{
Scanner in=new Scanner(System.in);
System.out.println("\n\n\t\t Welcome User\n");
System.out.println("Enter Folder location (e.x) C:\\\\Users\\\\mukunthan.g2\\\\Desktop\\\\New folder\\\\");
//System.out.println("(e.x) C:\\Users\\mukunthan.g2\\Desktop\\New folder\\");
String fi=in.next();
Scanner s = new Scanner(new File(fi.concat("1.txt")));
Scanner s1 = new Scanner(new File(fi.concat("2.txt")));
Scanner sku = new Scanner(new File(fi.concat("3.txt")));
File file = new File(fi.concat("output.txt"));
PrintWriter output = new PrintWriter(file);
ArrayList<String> list = new ArrayList<String>();
ArrayList<String> out1 = new ArrayList<String>();
while (s.hasNext()){
list.add(s.next());
}
s.close();
ArrayList<String> list1 = new ArrayList<String>();
while (s1.hasNext()){
list1.add(s1.next());
}
s.close();
ArrayList<String> skus = new ArrayList<String>();
while (sku.hasNext()){
skus.add(sku.next());
}
s.close();
int k=0;
list1.size();
for (int j=0;j<list1.size();j++)
{
String fu=list1.get(j);
String su=list.get(j);
try{
URL url = new URL(fu);
image = ImageIO.read(url);
ImageIO.write(image, "jpg",new File(fi.concat(("1.jpg"))));
}
catch (Exception e1)
{
BufferedImage originalImage = ImageIO.read(new File(fi.concat(("bk.jpg"))));
int type = originalImage.getType() == 0? BufferedImage.TYPE_INT_RGB : originalImage.getType();
BufferedImage resizeImageJpg = resizeImage(originalImage, type);
ImageIO.write(resizeImageJpg, "jpg", new File(fi.concat("1.jpg")));
}
try{
URL url1 = new URL(su);
image = ImageIO.read(url1);
ImageIO.write(image, "jpg",new File(fi.concat("2.jpg")));
}
catch (Exception e2)
{
BufferedImage originalImage = ImageIO.read(new File(fi.concat("wt.jpg")));
int type = originalImage.getType() == 0? BufferedImage.TYPE_INT_RGB : originalImage.getType();
BufferedImage resizeImageJpg = resizeImage(originalImage, type);
ImageIO.write(resizeImageJpg, "jpg", new File(fi.concat("5.jpg")));
}
for(int i=1;i<=2;i++)
{
if(i==1)
{
try{
BufferedImage originalImage = ImageIO.read(new File(fi.concat("1.jpg")));
int type = originalImage.getType() == 0? BufferedImage.TYPE_INT_RGB : originalImage.getType();
BufferedImage resizeImageJpg = resizeImage(originalImage, type);
ImageIO.write(resizeImageJpg, "jpg", new File(fi.concat("4.jpg")));
}
catch (Exception e)
{
BufferedImage originalImage = ImageIO.read(new File(fi.concat(fi.concat("bk.jpg"))));
int type = originalImage.getType() == 0? BufferedImage.TYPE_INT_RGB : originalImage.getType();
BufferedImage resizeImageJpg = resizeImage(originalImage, type);
ImageIO.write(resizeImageJpg, "jpg", new File(fi.concat("4.jpg")));
}
}
if(i==2)
{
try{
BufferedImage originalImage = ImageIO.read(new File(fi.concat("2.jpg")));
int type = originalImage.getType() == 0? BufferedImage.TYPE_INT_RGB : originalImage.getType();
BufferedImage resizeImageJpg = resizeImage(originalImage, type);
ImageIO.write(resizeImageJpg, "jpg", new File(fi.concat("5.jpg")));
}
catch (Exception e)
{
BufferedImage originalImage = ImageIO.read(new File(fi.concat("wt.jpg")));
int type = originalImage.getType() == 0? BufferedImage.TYPE_INT_RGB : originalImage.getType();
BufferedImage resizeImageJpg = resizeImage(originalImage, type);
ImageIO.write(resizeImageJpg, "jpg", new File(fi.concat("5.jpg")));
}
}
}
//color
BufferedImage biA= ImageIO.read(new File(fi.concat("4.jpg")));
DataBuffer dbA = biA.getData().getDataBuffer();
int sizeA = dbA.getSize();
//color
BufferedImage biB= ImageIO.read(new File(fi.concat("5.jpg")));
DataBuffer dbB = biB.getData().getDataBuffer();
int sizeB = dbB.getSize();
for(int i=1;i<=2;i++)
{
if(i==1)
{
BufferedImage input = ImageIO.read(new File(fi.concat("4.jpg")));
// Create a black-and-white image of the same size.
BufferedImage im =new BufferedImage(150,150,BufferedImage.TYPE_BYTE_BINARY);
// Get the graphics context for the black-and-white image.
Graphics2D g2d = im.createGraphics();
// Render the input image on it.
g2d.drawImage(input,0,0,null);
// Store the resulting image using the PNG format.
ImageIO.write(im,"jpg",new File(fi.concat("44.jpg")));
}
if(i==2)
{
BufferedImage input = ImageIO.read(new File(fi.concat("5.jpg")));
// Create a black-and-white image of the same size.
BufferedImage im =new BufferedImage(150,150,BufferedImage.TYPE_BYTE_BINARY);
// Get the graphics context for the black-and-white image.
Graphics2D g2d = im.createGraphics();
// Render the input image on it.
g2d.drawImage(input,0,0,null);
// Store the resulting image using the PNG format.
ImageIO.write(im,"jpg",new File(fi.concat("55.jpg")));
}}
BufferedImage fbw1= ImageIO.read(new File(fi.concat("44.jpg")));
DataBuffer db_fbw1 = fbw1.getData().getDataBuffer();
int sizeA_fbw1 = db_fbw1.getSize();
BufferedImage sbw1= ImageIO.read(new File(fi.concat("55.jpg")));
DataBuffer db_sbw1 = sbw1.getData().getDataBuffer();
int sizeA_sbw1 = db_sbw1.getSize();
int[] abw=new int[(sizeA_fbw1)];
int[] bbw=new int[(sizeA_fbw1)];
for(int i=0; i<(sizeA_fbw1); i++)
{
abw[i]=db_fbw1.getElem(i); bbw[i]=db_sbw1.getElem(i);
}
int lol=0;
int abw_tot=0; int bbw_tot=0;
for(int i=0; i<(sizeA_fbw1); i++)
{
abw_tot=abw_tot+abw[i]; bbw_tot=bbw_tot+bbw[i];
}
float fst_bw=(abw_tot-bbw_tot);
if(fst_bw<0) fst_bw=fst_bw*(-1);
float finalbw=((fst_bw/abw_tot)*100);
System.out.println(finalbw);
if(finalbw<15)
{
int[] a=new int[16875];
int[] b=new int[16875];
int[] c=new int[16875];
int[] d=new int[16875];
int[] w=new int[16875];
int[] x=new int[16875];
int[] y=new int[16875];
int[] z=new int[16875];
int lo=0;
for(int i=0; i<16875; i++)
{
a[lo]=dbA.getElem(i); w[lo]=dbB.getElem(i);
lo++;
}
lo=0;
for(int i=16875; i<(16874*2); i++)
{
b[lo]=dbA.getElem(i); x[lo]=dbB.getElem(i);
lo++;
}
lo=0;
for(int i=(16874*2); i<(16874*3); i++)
{
c[lo]=dbA.getElem(i); y[lo]=dbB.getElem(i);
lo++;
}
lo=0;
for(int i=(16874*3); i<(16874*4); i++)
{
d[lo]=dbA.getElem(i); z[lo]=dbB.getElem(i);
lo++;
}
float a1=0,b1=0,c1=0,d1=0,w1=0,x1=0,y1=0,z1=0;
for(int i=0; i<16875; i++)
{
a1=a[i]+a1; w1=w[i]+w1;
}
for(int i=0; i<16875; i++)
{
b1=b[i]+b1; x1=x[i]+x1;
}
for(int i=0; i<16875; i++)
{
c1=c[i]+c1; y1=y[i]+y1;
}
for(int i=0; i<16875; i++)
{
d1=d[i]+d1; z1=z[i]+z1;
}
float fst=(a1-w1);
float snd=(b1-x1);
float thd=(c1-y1);
float fth=(d1-z1);
if(fst<0) fst=fst*(-1);
if(snd<0) snd=snd*(-1);
if(thd<0) thd=thd*(-1);
if(fth<0) fth=fth*(-1);
float fst1=(w1-a1);
float snd1=(x1-b1);
float thd1=(y1-c1);
float fth1=(z1-d1);
if(fst1<0) fst1=fst1*(-1);
if(snd1<0) snd1=snd1*(-1);
if(thd1<0) thd1=thd1*(-1);
if(fth1<0) fth1=fth1*(-1);
float oo1=((fst1/a1)*100);
float oo2=((snd1/b1)*100);
float oo3=((thd1/c1)*100);
float oo4=((fth1/d1)*100);
float o1=((fst/a1)*100);
float o2=((snd/b1)*100);
float o3=((thd/c1)*100);
float o4=((fth/d1)*100);
String opt=new String("correct");
String opt1=new String("incorrect");
String result=null;
if (o1<15 && o2<15 && o3<15 && o4<15 )
{
if (oo1<15 && oo2<15 && oo3<15 && oo4<15 )
{
result=opt;
System.out.println(opt+" "+o1+" "+o2+" "+o3+" "+o4);
}
}
if (o1>15 || o2>15 || o3>15 || o4>15)
{
if (oo1>15 || oo2>15 || oo3>15 || oo4>15)
{
result=opt1;
System.out.println(opt1+" "+o1+" "+o2+" "+o3+" "+o4);
}
}
output.println(skus.get(j)+" " +result+" "+o1+" "+o2+" "+o3+" "+o4);
out1.add(result);
k++;
}
if(finalbw>15)
{
output.println(skus.get(j)+" incorrect");
}
}output.close();}
/*catch(Exception e)
{
System.out.println("error at "+(k+1) + " url");
output.close();
for (int i=0;i<out1.size();i++)
{
output.println(skus.get(i)+" "+out1.get(i));
}
}*/
}
Histogram deviation in java
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Scanner;
import javax.imageio.ImageIO;
public class own {
private static BufferedImage image;
private static final int IMG_WIDTH = 100;
private static final int IMG_HEIGHT = 100;
private static BufferedImage resizeImage(BufferedImage originalImage, int type){
BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
g.dispose();
return resizedImage;
}
public static void main(String[] args) throws IOException
{
Scanner s = new Scanner(new File("C:\\Users\\manoj\\Desktop\\1.txt"));
Scanner s1 = new Scanner(new File("C:\\Users\\manoj\\Desktop\\2.txt"));
ArrayList<String> list = new ArrayList<String>();
while (s.hasNext()){
list.add(s.next());
}
s.close();
ArrayList<String> list1 = new ArrayList<String>();
while (s1.hasNext()){
list1.add(s1.next());
}
s.close();
int n=list1.size();
for (int j=0;j<n;j++)
{
String fu=list1.get(j);
String su=list.get(j);
URL url = new URL(fu);
image = ImageIO.read(url);
ImageIO.write(image, "jpg",new File("C:\\Users\\manoj\\Desktop\\1.jpg"));
URL url1 = new URL(su);
image = ImageIO.read(url1);
ImageIO.write(image, "jpg",new File("C:\\Users\\manoj\\Desktop\\2.jpg"));
for(int i=1;i<=2;i++)
{
if(i==1)
{
BufferedImage originalImage = ImageIO.read(new File("C:\\Users\\manoj\\Desktop\\1.jpg"));
int type = originalImage.getType() == 0? BufferedImage.TYPE_INT_ARGB : originalImage.getType();
BufferedImage resizeImageJpg = resizeImage(originalImage, type);
ImageIO.write(resizeImageJpg, "jpg", new File("C:\\Users\\manoj\\Desktop\\4.jpg"));
}
if(i==2)
{
BufferedImage originalImage = ImageIO.read(new File("C:\\Users\\manoj\\Desktop\\2.jpg"));
int type = originalImage.getType() == 0? BufferedImage.TYPE_INT_ARGB : originalImage.getType();
BufferedImage resizeImageJpg = resizeImage(originalImage, type);
ImageIO.write(resizeImageJpg, "jpg", new File("C:\\Users\\manoj\\Desktop\\5.jpg"));
}
}
BufferedImage biA= ImageIO.read(new File("C:\\Users\\manoj\\Desktop\\4.jpg"));
DataBuffer dbA = biA.getData().getDataBuffer();
int sizeA = dbA.getSize();
BufferedImage biB= ImageIO.read(new File("C:\\Users\\manoj\\Desktop\\5.jpg"));
DataBuffer dbB = biB.getData().getDataBuffer();
int sizeB = dbB.getSize();
int[] a =new int[sizeA];
int[] b=new int[sizeB];
int a1=0, b1=0;
for(int i=0; i<sizeA; i++) {
a[i]=dbA.getElem(i);
}
for(int i=0; i<sizeB; i++) {
b[i]=dbB.getElem(i);
}
for(int i=0; i<sizeA; i++)
{
if(a[i]==255)
a1=0+a1;
else
a1=a[i]+a1;
}
for(int i=0; i<sizeB; i++)
{
if(b[i]==255)
b1=0+b1;
else
b1=b[i]+b1;
}
int o1= (a1/sizeA);
int o2=(b1/sizeB);
int dev=(o1-o2);
System.out.println("Histogram deviation is "+(dev));
n++;
}
}
}
Resizing multiple images using MATLAB
Get all the image files that are need to be re sized in matlab current directory and run this code
dirData = dir('*.jpg');
fileNames = {dirData.name};
for iFile = 1:numel(fileNames)
newName = sprintf('%1d.jpg',iFile);
movefile(fileNames{iFile},newName);
end
After renaming the files (by running above program ) run this code
q=1;
p=1;
for i=1:10
oq=imread(strcat(num2str(q),'.jpg'));
odprz=imresize(oq,[150 150]); %# specify your size here
imwrite(odprz,strcat(num2str(p),'.png'));
q=q+1;
p=p+1;
end
collect only .png format files.That files are re-sized files.
Automated image comparison using MATLAB
Automated image
comparison using MATLAB
MAIN MOTIVE
This project presents the new machine learning process on images. In competitive intelligence information comparison the text analytic decides the product match type to enhance that automation process image comparison of the products is automated and presented here. Here the corner detection and comparison on images is used to compare the images.
USE
CASES
Mainly developed
for competitive intelligence (i.e.) to compare online marketing client and
competitor images.
Considerations
To compare images in large amount if we download images and compare the
space needed will be more to overcome that scenario the image URLs are used
from both client and competitor side. Images can be of any format in the case
of comparison of images from URLs.
If input is image URLs mean that should be in excel file and output
status of images equal or not equal will be stored in the specified column of
excel sheet.
If images are stored in drives mean other process like renaming of images
will be followed to get the images into the code execution. (Pre-processing is needed)
PROCESS
FLOW
Example images processed
COMPARISON DURING EXECUTION
OUTPUT
output will be stored in excel sheet.
status 1: equal
status 2: not equal
*********************************************************************************
q=2; %% source image name ('2.jpg')
w=2; %% another image ('2.png')
sd=1;
for i=1:1
hIdtc = video.ImageDataTypeConverter();
hCsc = video.ColorSpaceConverter('Conversion','RGB to intensity');
oq=imread(strcat(num2str(q),'.jpg'));
odprz=imresize(oq,[150 150]);
imwrite(odprz,'oq1.jpg');
leftI3chan = step(hIdtc,imread('oq1.jpg'));
leftI = step(hCsc,leftI3chan);
disp(leftI)
sw=imread(strcat(num2str(w),'.png'));
stprz=imresize(sw,[150 150]);
imwrite(stprz,'sw1.png');
rightI3chan = step(hIdtc,imread('sw1.png'));
rightI = step(hCsc,rightI3chan);
harris = video.CornerDetector( 'MaximumCornerCount', 1000, ...
'CornerThreshold', 1e-4, ...
'NeighborhoodSize', [9 9] );
pointsLeft = flipud(step(harris, leftI))+1;
pointsRight = flipud(step(harris, rightI))+1;
% Trim point lists to minimum size.
pointsLeft = pointsLeft(:, 1:find(all(pointsLeft==1,1),1) - 1);
pointsRight = pointsRight(:, 1:find(all(pointsRight==1,1),1) - 1);
halfBlockSize = 4; % Block half-size.
blockSize = 2*halfBlockSize+1; % Full block size.
[r,c] = size(leftI);
matchThreshold = 0.7;
% Extract features for pointsRight
features = zeros(blockSize^2,size(pointsRight,2), 'single');
for i=1:size(pointsRight,2)
T = zeros(blockSize, 'single');
minr = max(1,pointsRight(2,i)-halfBlockSize);
maxr = min(r,pointsRight(2,i)+halfBlockSize);
minc = max(1,pointsRight(1,i)-halfBlockSize);
maxc = min(c,pointsRight(1,i)+halfBlockSize);
T( halfBlockSize+1-(pointsRight(2,i)-minr):halfBlockSize+1+(maxr-pointsRight(2,i)), ...
halfBlockSize+1-(pointsRight(1,i)-minc):halfBlockSize+1+(maxc-pointsRight(1,i)) ) = ...
rightI( minr:maxr, minc:maxc );
features(:,i) = T(:);
end
% Loop over pointsLeft, looking for best matches in pointsRight via features.
ix1 = zeros(1,size(pointsLeft,2), 'single');
d = zeros(size(ix1), 'single');
for i=1:size(pointsLeft,2)
T = zeros(blockSize, 'single');
minr = max(1,pointsLeft(2,i)-halfBlockSize);
maxr = min(r,pointsLeft(2,i)+halfBlockSize);
minc = max(1,pointsLeft(1,i)-halfBlockSize);
maxc = min(c,pointsLeft(1,i)+halfBlockSize);
T( halfBlockSize+1-(pointsLeft(2,i)-minr):halfBlockSize+1+(maxr-pointsLeft(2,i)), ...
halfBlockSize+1-(pointsLeft(1,i)-minc):halfBlockSize+1+(maxc-pointsLeft(1,i)) ) = ...
leftI( minr:maxr, minc:maxc );
% Find matching point in pointsRight with features features.
[v,ix] = min( sum(bsxfun(@minus,features,T(:)).^2,1) );
if v < matchThreshold
ix1(i) = ix;
end
end
% Extract indices of matched points on each side.
ix2 = nonzeros(ix1);
ix1 = find(ix1);
% Create subselected, homogenized point lists.
pointsLeftH = [double(pointsLeft(:,ix1)); ones(1,length(ix1), 'single')];
pointsRightH = [double(pointsRight(:,ix2)); ones(1,length(ix2), 'single')];
figure(1), clf;
imshow(cat(3,rightI,leftI,leftI)), hold on;
plot(pointsLeftH(1,:),pointsLeftH(2,:),'x','Color',[0 0 1],'MarkerSize',8);
plot(pointsRightH(1,:),pointsRightH(2,:),'x','Color',[1 1 0],'MarkerSize',8);
plot([pointsLeftH(1,:);pointsRightH(1,:)],...
[pointsLeftH(2,:);pointsRightH(2,:)],'-','Color',[0 1 0]);
set(gca,'XTick',[],'YTick',[]);
title('Initial corresponded points between the two images');
d1=mean(pointsRightH);
d2=mean(pointsRightH);
t1=mode(d2);
t2=mode(d1);
if t1 == t2 %% modify here put one extra loop if t1<5 means result will be not a match(for better comparison)
result={'exact'};
disp(result)
else
result={'not found'};
disp(result)
end
xlswrite('myfile.xls',result,'sheet1',strcat('A',num2str(sd))) %% excel file to store result
q=q+1;
w=w+1;
sd=sd+1;
end
*********************************************************************************
q=2; %% source image name ('2.jpg')
w=2; %% another image ('2.png')
sd=1;
for i=1:1
hIdtc = video.ImageDataTypeConverter();
hCsc = video.ColorSpaceConverter('Conversion','RGB to intensity');
oq=imread(strcat(num2str(q),'.jpg'));
odprz=imresize(oq,[150 150]);
imwrite(odprz,'oq1.jpg');
leftI3chan = step(hIdtc,imread('oq1.jpg'));
leftI = step(hCsc,leftI3chan);
disp(leftI)
sw=imread(strcat(num2str(w),'.png'));
stprz=imresize(sw,[150 150]);
imwrite(stprz,'sw1.png');
rightI3chan = step(hIdtc,imread('sw1.png'));
rightI = step(hCsc,rightI3chan);
harris = video.CornerDetector( 'MaximumCornerCount', 1000, ...
'CornerThreshold', 1e-4, ...
'NeighborhoodSize', [9 9] );
pointsLeft = flipud(step(harris, leftI))+1;
pointsRight = flipud(step(harris, rightI))+1;
% Trim point lists to minimum size.
pointsLeft = pointsLeft(:, 1:find(all(pointsLeft==1,1),1) - 1);
pointsRight = pointsRight(:, 1:find(all(pointsRight==1,1),1) - 1);
halfBlockSize = 4; % Block half-size.
blockSize = 2*halfBlockSize+1; % Full block size.
[r,c] = size(leftI);
matchThreshold = 0.7;
% Extract features for pointsRight
features = zeros(blockSize^2,size(pointsRight,2), 'single');
for i=1:size(pointsRight,2)
T = zeros(blockSize, 'single');
minr = max(1,pointsRight(2,i)-halfBlockSize);
maxr = min(r,pointsRight(2,i)+halfBlockSize);
minc = max(1,pointsRight(1,i)-halfBlockSize);
maxc = min(c,pointsRight(1,i)+halfBlockSize);
T( halfBlockSize+1-(pointsRight(2,i)-minr):halfBlockSize+1+(maxr-pointsRight(2,i)), ...
halfBlockSize+1-(pointsRight(1,i)-minc):halfBlockSize+1+(maxc-pointsRight(1,i)) ) = ...
rightI( minr:maxr, minc:maxc );
features(:,i) = T(:);
end
% Loop over pointsLeft, looking for best matches in pointsRight via features.
ix1 = zeros(1,size(pointsLeft,2), 'single');
d = zeros(size(ix1), 'single');
for i=1:size(pointsLeft,2)
T = zeros(blockSize, 'single');
minr = max(1,pointsLeft(2,i)-halfBlockSize);
maxr = min(r,pointsLeft(2,i)+halfBlockSize);
minc = max(1,pointsLeft(1,i)-halfBlockSize);
maxc = min(c,pointsLeft(1,i)+halfBlockSize);
T( halfBlockSize+1-(pointsLeft(2,i)-minr):halfBlockSize+1+(maxr-pointsLeft(2,i)), ...
halfBlockSize+1-(pointsLeft(1,i)-minc):halfBlockSize+1+(maxc-pointsLeft(1,i)) ) = ...
leftI( minr:maxr, minc:maxc );
% Find matching point in pointsRight with features features.
[v,ix] = min( sum(bsxfun(@minus,features,T(:)).^2,1) );
if v < matchThreshold
ix1(i) = ix;
end
end
% Extract indices of matched points on each side.
ix2 = nonzeros(ix1);
ix1 = find(ix1);
% Create subselected, homogenized point lists.
pointsLeftH = [double(pointsLeft(:,ix1)); ones(1,length(ix1), 'single')];
pointsRightH = [double(pointsRight(:,ix2)); ones(1,length(ix2), 'single')];
figure(1), clf;
imshow(cat(3,rightI,leftI,leftI)), hold on;
plot(pointsLeftH(1,:),pointsLeftH(2,:),'x','Color',[0 0 1],'MarkerSize',8);
plot(pointsRightH(1,:),pointsRightH(2,:),'x','Color',[1 1 0],'MarkerSize',8);
plot([pointsLeftH(1,:);pointsRightH(1,:)],...
[pointsLeftH(2,:);pointsRightH(2,:)],'-','Color',[0 1 0]);
set(gca,'XTick',[],'YTick',[]);
title('Initial corresponded points between the two images');
d1=mean(pointsRightH);
d2=mean(pointsRightH);
t1=mode(d2);
t2=mode(d1);
if t1 == t2 %% modify here put one extra loop if t1<5 means result will be not a match(for better comparison)
result={'exact'};
disp(result)
else
result={'not found'};
disp(result)
end
xlswrite('myfile.xls',result,'sheet1',strcat('A',num2str(sd))) %% excel file to store result
q=q+1;
w=w+1;
sd=sd+1;
end
********************************** THANK YOU***********************************
Your valid suggestions are anticipated to enhance the program.
LINKED IN : in.linkedin.com/in/srimukunthan
GMAIL : srimukunthan@gmail.com
FACEBOOK: www.facebook.com/mukunthan.gj







