Skip to content

Commit

Permalink
core: add PSNR() function
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Oct 20, 2023
1 parent 56dff7a commit bb4bb29
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Your pull requests will be greatly appreciated!
- [X] [PCABackProject](https://docs.opencv.org/master/d2/de8/group__core__array.html#gab26049f30ee8e94f7d69d82c124faafc)
- [X] [PCACompute](https://docs.opencv.org/master/d2/de8/group__core__array.html#ga4e2073c7311f292a0648f04c37b73781)
- [X] [PCAProject](https://docs.opencv.org/master/d2/de8/group__core__array.html#ga6b9fbc7b3a99ebfd441bbec0a6bc4f88)
- [ ] [PSNR](https://docs.opencv.org/master/d2/de8/group__core__array.html#ga07aaf34ae31d226b1b847d8bcff3698f)
- [X] [PSNR](https://docs.opencv.org/master/d2/de8/group__core__array.html#ga07aaf34ae31d226b1b847d8bcff3698f)
- [X] [randn](https://docs.opencv.org/master/d2/de8/group__core__array.html#gaeff1f61e972d133a04ce3a5f81cf6808)
- [X] [randShuffle](https://docs.opencv.org/master/d2/de8/group__core__array.html#ga6a789c8a5cb56c6dd62506179808f763)
- [X] [randu](https://docs.opencv.org/master/d2/de8/group__core__array.html#ga1ba1026dca0807b27057ba6a49d258c0)
Expand Down
4 changes: 4 additions & 0 deletions core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,10 @@ void Mat_PCAProject(Mat data, Mat mean, Mat eigenvectors, Mat result) {
cv::PCAProject(*data, *mean, *eigenvectors, *result);
}

double PSNR(Mat src1, Mat src2) {
return cv::PSNR(*src1, *src2);
}

void Mat_Exp(Mat src, Mat dst) {
cv::exp(*src, *dst);
}
Expand Down
8 changes: 8 additions & 0 deletions core.go
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,14 @@ func PCAProject(data Mat, mean Mat, eigenvectors Mat, result *Mat) {
C.Mat_PCAProject(data.p, mean.p, eigenvectors.p, result.p)
}

// PSNR computes the Peak Signal-to-Noise Ratio (PSNR) image quality metric.
//
// For further details, please see:
// https://docs.opencv.org/4.x/d2/de8/group__core__array.html#ga3119e3ea73010a6f810bb05aa36ac8d6
func PSNR(src1 Mat, src2 Mat) float64 {
return float64(C.PSNR(src1.p, src2.p))
}

// Exp calculates the exponent of every array element.
//
// For further details, please see:
Expand Down
1 change: 1 addition & 0 deletions core.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ void Mat_EigenNonSymmetric(Mat src, Mat eigenvalues, Mat eigenvectors);
void Mat_PCABackProject(Mat data, Mat mean, Mat eigenvectors, Mat result);
void Mat_PCACompute(Mat src, Mat mean, Mat eigenvectors, Mat eigenvalues, int maxComponents);
void Mat_PCAProject(Mat data, Mat mean, Mat eigenvectors, Mat result);
double PSNR(Mat src1, Mat src2);
void Mat_Exp(Mat src, Mat dst);
void Mat_ExtractChannel(Mat src, Mat dst, int coi);
void Mat_FindNonZero(Mat src, Mat idx);
Expand Down
13 changes: 13 additions & 0 deletions core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2162,6 +2162,19 @@ func TestPCAProject(t *testing.T) {
}
}

func TestPSNR(t *testing.T) {
src := IMRead("images/gocvlogo.jpg", IMReadColor)
if src.Empty() {
t.Error("Invalid read of Source Mat in PSNR test")
}
defer src.Close()

result := PSNR(src, src)
if result == 0 {
t.Error("Unexpected PSNR of 0")
}
}

func TestMatExp(t *testing.T) {
src := NewMatWithSize(10, 10, MatTypeCV32F)
dst := NewMat()
Expand Down

0 comments on commit bb4bb29

Please sign in to comment.