This repository has been archived by the owner on Feb 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
task3.h
89 lines (73 loc) · 1.75 KB
/
task3.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#pragma once
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc.hpp>
#include<opencv2/imgcodecs.hpp>
#include<iostream>
#include <stdio.h>
#include<cmath>
#include"task1.h"
using namespace cv;
using namespace std;
void diceCof(Mat gt, Mat img)
{
float fp=0, tp=0, fn=0, dice=0, num1=0, num2=0;
int cols = img.cols;
int rows = img.rows;
int** image = new int* [rows];
for (int i = 0; i < rows; i++)
{
image[i] = new int[cols];
}
int** truth = new int* [rows];
for (int i = 0; i < rows; i++)
{
truth[i] = new int[cols];
}
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
image[i][j] = (int)img.at<uchar>(i, j);
truth[i][j] = (int)gt.at<uchar>(i, j);
}
}
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
if (image[i][j] == 255)
if(truth[i][j]==255)
{
tp++;
}
if (image[i][j] ==255)
if(truth[i][j]!=255)
{
fp++;
}
}
}
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
if (image[i][j] == 255)
{
num1++;
}
if (truth[i][j] == 255)
{
num2++;
}
}
}
if (num1 > num2) {
fn = num1 - num2;
}
else
fn = 0;
dice = (2 * tp) / (fn + (2 * tp) + fp);
cout << "The Dice Coefficient is : " << dice << endl;
}