hi, i'm work on image comparison. i'm using the similarity measurement which i need to:
1) convert the image into the binary form since the algorithm that i've use works with binary data for the computation
2) compare the string binary data to get the similarity or dissimilarity result.
The problem is, i already done with the image (jpg) conversion to binary and also try the algorithm structure in C# language, but i having a problem to getvalue from the string of binary to pass with the comparison function where i declare as Bitmap since the comparison took the height and width of the image first. Then the comparison is between each rows of the two image.
example:
Image Binary Values (row operation)
Image1 1 1 1 1
Image2 0 1 0 0
the calculation is to compare the strings of binary from the two image.
p = positive both image ---> [1 1]
q = positive image1 , negative image2 ---> [1 0]
r = negative image1, positive image1 ---> [0 1]
therefore,
results from the image comparison above :
p = 1
q = 3
r = 0
i need to get the result example above so that i can calculate to measure the similarity between image.
i really new to this language and i really appreciate with the help. i'm also attach the code that i already done and sample of interface from my program. thank you.
1) convert the image into the binary form since the algorithm that i've use works with binary data for the computation
2) compare the string binary data to get the similarity or dissimilarity result.
The problem is, i already done with the image (jpg) conversion to binary and also try the algorithm structure in C# language, but i having a problem to getvalue from the string of binary to pass with the comparison function where i declare as Bitmap since the comparison took the height and width of the image first. Then the comparison is between each rows of the two image.
example:
Image Binary Values (row operation)
Image1 1 1 1 1
Image2 0 1 0 0
the calculation is to compare the strings of binary from the two image.
p = positive both image ---> [1 1]
q = positive image1 , negative image2 ---> [1 0]
r = negative image1, positive image1 ---> [0 1]
therefore,
results from the image comparison above :
p = 1
q = 3
r = 0
i need to get the result example above so that i can calculate to measure the similarity between image.
i really new to this language and i really appreciate with the help. i'm also attach the code that i already done and sample of interface from my program. thank you.
Code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace ShapeRecognition { public partial class Form1 : Form { Bitmap fname1, fname2; Bitmap img1, img2; String textb = ""; String texto = ""; float p, q, r, jd; int sum1 = 0, sum2 = 0, sum3 = 0; bool flag = true; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { progressBar1.Visible = false; } private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { openFileDialog1.FileName = ""; openFileDialog1.Title = "Images"; openFileDialog1.Filter = "All Images|*.jpg; *.bmp; *.png";// openFileDialog1.ShowDialog(); if (openFileDialog1.FileName.ToString() != "") { Box1.ImageLocation = openFileDialog1.FileName.ToString(); fname1 = new Bitmap(openFileDialog1.FileName.ToString()); } } private void button1_Click(object sender, EventArgs e) { for (int i = 0; i < fname1.Height; i++) { for (int j = 0; j < fname1.Width; j++) { if (fname1.GetPixel(j, i).A.ToString() == "255" && fname1.GetPixel(j, i).B.ToString() == "255" && fname1.GetPixel(j, i).G.ToString() == "255" && fname1.GetPixel(j, i).R.ToString() == "255") { texto = texto + "0"; } else { texto = texto + "1"; } } texto = texto + "\r\n"; } text1.Text = texto; } private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { openFileDialog2.FileName = ""; openFileDialog2.Title = "Images"; openFileDialog2.Filter = "All Images|*.jpg; *.bmp; *.png";// openFileDialog2.ShowDialog(); if (openFileDialog1.FileName.ToString() != "") { Box2.ImageLocation = openFileDialog2.FileName.ToString(); fname2 = new Bitmap(openFileDialog2.FileName.ToString()); } } private void button2_Click(object sender, EventArgs e) { for (int i = 0; i < fname2.Height; i++) { for (int j = 0; j < fname2.Width; j++) { if (fname2.GetPixel(j, i).A.ToString() == "255" && fname2.GetPixel(j, i).B.ToString() == "255" && fname2.GetPixel(j, i).G.ToString() == "255" && fname2.GetPixel(j, i).R.ToString() == "255") { textb = textb + "0"; } else { textb = textb + "1"; } } textb = textb + "\r\n"; } text2.Text = textb; } private void button3_Click(object sender, EventArgs e) { progressBar1.Visible = true; string img1_ref, img2_ref; [B] img1 = new Bitmap (texto); img2 = new Bitmap (textb);[/B] progressBar1.Maximum = img1.Width; if (img1.Width == img2.Width && img1.Height == img2.Height) { for (int i = 0; i < img1.Width; i++) { for (int j = 0; j < img1.Height; j++) { img1_ref = img1.GetPixel(i, j).ToString(); img2_ref = img2.GetPixel(i, j).ToString(); if (img1_ref == "1" && img2_ref == "1") { sum1++; } else if (img1_ref =="1" && img2_ref =="0") { sum2++; } else if (img1_ref =="0" && img2_ref =="1") { sum3++; } } p = sum1; q = sum2; r = sum3; jd = (q + r) / (p + q + r); if (jd < 0.75 ) MessageBox.Show ("Images are dissimilar," +jd+ "ratio results"); else if ( jd == 0.75 || jd <= 1) MessageBox.Show ("Images are similar," +jd+ "ratio results"); } MessageBox.Show("can not compare this images"); this.Dispose(); } } } }
Comment