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. - 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;
-
img1 = new Bitmap (texto);
-
img2 = new Bitmap (textb);
-
-
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();
-
-
}
-
-
-
-
}
-
}
-
}
6 4198 TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Bitmaps don't just create from a string.
You either need a full stream of bytes that describe the bitmap, or you need to create a new bitmap and set every pixel based on the data string
thanks Plater but i really need help more elaboration about your suggestion, could you explain more? i'm sorry and i really appreciate it.
Step 1: Open MSDN and actually LOOK at the bitmap object.
Step 2: Step one should cover it
EDIT: Ok, that's not really fair of me I suppose.
The bitmap object can be created from a stream. If you have a byte[], you can turn it into a stream with the MemoryStream, which can be accepted by the Bitmap object.
Otherwise, you create a bitmap of the correct size and then cycle through your data, decide what pixel the data is for, pick the color and the set the pixel in the bitmap.
hi Plater, thanks for the feedback.already search and do what you have been suggest for. i also have try another code. i manage to get value from the string of binary and run through the algorithm. but another problem occur where once the result appear, suppose i got the to total answer is 64 but the result shows 32.
--> i have done the tracing to check where the error occur, the looping where comparison function produce incorrect result. the comparison of first row is correct but when it loop, the next row produce wrong result and so on.
--> i really need help since i need to present this testing sooner by tomorrow. could you help me?
--> sorry once again and i really wait for the reply. thank you so much.
--> here i attach the new 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 JaccardRecognition
-
{
-
public partial class shape : Form
-
{
-
-
-
Bitmap Image1, Image2;
-
String textImage1 = "";
-
String textImage2 = "";
-
float a, b, p, q, r, jd;
-
int sum1 = 0, sum2 = 0, sum3 = 0;
-
-
-
-
-
public shape()
-
{
-
InitializeComponent();
-
}
-
-
private void Form1_Load(object sender, EventArgs e)
-
{
-
-
}
-
-
/*Open and read the first image*/
-
-
private void OpenFirstImageBttn_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();
-
Image1 = new Bitmap(openFileDialog1.FileName.ToString());
-
string h = Convert.ToString(Image1.Height);
-
string w = Convert.ToString(Image1.Width);
-
displayh.Text = h;
-
displayw.Text = w;
-
}
-
-
}
-
-
-
-
/*Covert first image into binary*/
-
-
private void convertImage1_Click(object sender, EventArgs e)
-
{
-
-
for (int i = 0; i < Image1.Height; i++)
-
{
-
for (int j = 0; j < Image1.Width; j++)
-
{
-
if (Image1.GetPixel(j, i).A.ToString() == "255" && Image1.GetPixel(j, i).B.ToString() == "255" && Image1.GetPixel(j, i).G.ToString() == "255" && Image1.GetPixel(j, i).R.ToString() == "255")
-
{
-
textImage1 = textImage1 + "0";
-
-
}
-
else
-
{
-
textImage1 = textImage1 + "1";
-
-
}
-
-
}
-
textImage1 = textImage1 + "\r\n";
-
}
-
-
text1.Text = textImage1;
-
}
-
-
/*Open and read the second image*/
-
-
private void OpenSecondImageBttn_LinkClicked_1(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();
-
Image2 = new Bitmap(openFileDialog2.FileName.ToString());
-
}
-
}
-
-
-
-
/*Covert second image into binary*/
-
-
private void convertImage2_Click(object sender, EventArgs e)
-
{
-
-
-
for (int i = 0; i < Image2.Height; i++)
-
{
-
for (int j = 0; j < Image2.Width; j++)
-
{
-
if (Image2.GetPixel(j, i).A.ToString() == "255" && Image2.GetPixel(j, i).B.ToString() == "255" && Image2.GetPixel(j, i).G.ToString() == "255" && Image2.GetPixel(j, i).R.ToString() == "255")
-
{
-
textImage2 = textImage2 + "0";
-
-
}
-
else
-
{
-
textImage2 = textImage2 + "1";
-
-
}
-
-
}
-
textImage2 = textImage2 + "\r\n";
-
}
-
-
text2.Text = textImage2;
-
}
-
-
/*This will compare both image from the binary data to check the similatiry measure */
-
/*Retrieve data in binary form to compute
-
--> The image size 16x16 pixels
-
--> looping the image 16 times where the comparison between in rows operation*/
-
-
private void button3_Click(object sender, EventArgs e)
-
{
-
-
string output1 = "";
-
string output2 = "";
-
-
string img1_ref = "";
-
string img2_ref = "";
-
-
output1 = Convert.ToString(textImage1);
-
output2 = Convert.ToString(textImage2);
-
-
-
if (output1.Length == output2.Length)
-
{
-
-
for (int i = 0; i < 16; i++) // looping the height image
-
{
-
for (int j = 0; j < 16; j++) // looping the length image character
-
{
-
img1_ref = output1[j].ToString();
-
img2_ref = output2[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++;
-
}
-
-
}
-
-
}
-
-
/* Jaccard measurement*/
-
p = sum1;
-
q = sum2;
-
r = sum3;
-
-
a = q + r;
-
b = p + q + r;
-
jd = a / b;
-
-
string valueP = Convert.ToString(p);
-
string valueQ = Convert.ToString(q);
-
string valueR = Convert.ToString(r);
-
string valueA = Convert.ToString(a);
-
string valueB = Convert.ToString(b);
-
text3.Text = valueP;
-
text4.Text = valueQ;
-
text5.Text = valueR;
-
textqr.Text = valueA;
-
textpqr.Text = valueB;
-
-
-
if (jd == 0 || jd < 0.15)
-
{
-
MessageBox.Show("Images are similar,ratio results:" + jd);
-
-
}
-
else if (jd == 0.15 || jd <= 1)
-
{
-
MessageBox.Show("Images are dissimilar,ratio results:" + jd);
-
-
}
-
-
else
-
MessageBox.Show("can not compare this images");
-
-
}
-
-
this.Dispose();
-
-
}
-
-
-
}
-
}
-
Well I think going the byte[] route would be a better choice, bitmap data sometimes has padded bytes to each "row", there's a term for it but I forget it.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: TOI DAY |
last post by:
I am badly in need of a routine to binary compare two large files. The
boolean result true/false would do. Can anyone help out with the code?
Thanks in advance
|
by: TOI DAY |
last post by:
I am badly in need of a routine to binary compare two large files. The
boolean result true/false would do. Can anyone help out with the code?
Thanks in advance
|
by: Wiktor Zychla |
last post by:
Hi there,
when stored in the binaries (or in metadata), strings are represented in
a special format: the length is followed by the string data.
However, I do not quite understand this...
|
by: John Hoffman |
last post by:
Reading registry:
....
RegistryKey rksub = rkey.OpenSubKey(s);
String valstr = rksub.GetValueNames();
foreach (String vs in valstr)
{
String vstr = rksub.GetValue(vs).ToString();
OR
String...
|
by: Abhijit |
last post by:
Hi,
I am facing problem in retriving value of a registry key where the value is
of type REG_QWORD.
Below is the code snipet i am trying with:
RegistryKey reg = Registry.CurrentUser;...
|
by: ABC |
last post by:
How to convert a date string to datetime value with custom date format?
e.g.
Date String Date Format Result (DateTime value)
"05/07/2004" "MM/dd/yyyy" May 7, 2004
"01062005" ...
|
by: http://www.visual-basic-data-mining.net/forum |
last post by:
Hi...
Say i have this string call "data" in Form1, this string contains number "5"
value....
how do i pass this string to the Form2 and compare with the combo box
items...
The combo box ...
|
by: abcabcabc |
last post by:
I write an application which can let user define own date format to input,
How to convert the date string to date value with end-user defined date
format?
Example, User Defined Date Format as...
|
by: Aman JIANG |
last post by:
hi
i need a fast way to do lots of conversion that between
string and numerical value(integer, float, double...), and
boost::lexical_cast is useless, because it runs for a long time,
(about 60...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
|
by: ezappsrUS |
last post by:
Hi,
I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
|
by: F22F35 |
last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...
| |