Giter Club home page Giter Club logo

Comments (2)

Kumataro avatar Kumataro commented on June 12, 2024

Hello, I feel it is python binding limitation, but it is not easy to fix.
To work your program, could you update to use "gray image" and "array of images" ?

import cv2
import numpy as np

base_image = cv2.imread("test.pnm", cv2.IMREAD_GRAYSCALE) # 1ch
temp = np.zeros(base_image.shape, np.uint8)
cv2.denoise_TVL1( [base_image], temp, lambda_=0.5, niters=30) # vector Mat
cv2.imwrite("dst.pnm", temp)

Array of images

This function denose_TVL1 requests array of images source, not single image.
https://docs.opencv.org/4.x/d1/d79/group__photo__denoise.html#ga7602ed5ae17b7de40152b922227c4e4f

void cv::denoise_TVL1 ( const std::vector< Mat > & observations

When single image is inputted, it splits into array of small images at python binding. (maybe it is limitation).
(640 x1x480) image is converted into (640x1) 480 images.
This array of image is used in other functions too. So it is not easy to customize for only this function.

Grayscale

If I missed, I'm sorry. But I think this function accept only 1ch images.
When debug build, CV_DbgAssert( elemSize() == sizeof(_Tp) ) will be failed.
( I feel It is better to check num of channels in denoise_TVL1() )

109
110                 //Rs = clip(Rs + sigma*(X-imgs), -clambda, clambda)
111                 for(count=0;count<(int)Rs.size();count++){
112                     transform<MatIterator_<double>,MatConstIterator_<uchar>,MatIterator_<double>,AddFloatToCharScaled>(
113                             Rs[count].begin(),Rs[count].end(),observations[count].begin<uchar>(),
114                             Rs[count].begin(),AddFloatToCharScaled(-sigma/255.0));
115                     Rs[count]+=sigma*X;
116                     min(Rs[count],clambda,Rs[count]);
117                     max(Rs[count],-clambda,Rs[count]);

1009    template<typename _Tp> inline
1010    MatConstIterator_<_Tp> Mat::begin() const
1011    {
1012        if (empty())
1013            return MatConstIterator_<_Tp>();
1014        CV_DbgAssert( elemSize() == sizeof(_Tp) );
1015        return MatConstIterator_<_Tp>((const Mat_<_Tp>*)this);
1016    }
1017
1018    template<typename _Tp> inline

(gdb) p elemSize()
$1 = 3
(gdb) p sizeof(_Tp)
$2 = 1

from opencv.

ncuxzy avatar ncuxzy commented on June 12, 2024

Hello, I feel it is python binding limitation, but it is not easy to fix. To work your program, could you update to use "gray image" and "array of images" ?

import cv2
import numpy as np

base_image = cv2.imread("test.pnm", cv2.IMREAD_GRAYSCALE) # 1ch
temp = np.zeros(base_image.shape, np.uint8)
cv2.denoise_TVL1( [base_image], temp, lambda_=0.5, niters=30) # vector Mat
cv2.imwrite("dst.pnm", temp)

Array of images

This function denose_TVL1 requests array of images source, not single image. https://docs.opencv.org/4.x/d1/d79/group__photo__denoise.html#ga7602ed5ae17b7de40152b922227c4e4f

void cv::denoise_TVL1 ( const std::vector< Mat > & observations

When single image is inputted, it splits into array of small images at python binding. (maybe it is limitation). (640 x1x480) image is converted into (640x1) 480 images. This array of image is used in other functions too. So it is not easy to customize for only this function.

Grayscale

If I missed, I'm sorry. But I think this function accept only 1ch images. When debug build, CV_DbgAssert( elemSize() == sizeof(_Tp) ) will be failed. ( I feel It is better to check num of channels in denoise_TVL1() )

109
110                 //Rs = clip(Rs + sigma*(X-imgs), -clambda, clambda)
111                 for(count=0;count<(int)Rs.size();count++){
112                     transform<MatIterator_<double>,MatConstIterator_<uchar>,MatIterator_<double>,AddFloatToCharScaled>(
113                             Rs[count].begin(),Rs[count].end(),observations[count].begin<uchar>(),
114                             Rs[count].begin(),AddFloatToCharScaled(-sigma/255.0));
115                     Rs[count]+=sigma*X;
116                     min(Rs[count],clambda,Rs[count]);
117                     max(Rs[count],-clambda,Rs[count]);

1009    template<typename _Tp> inline
1010    MatConstIterator_<_Tp> Mat::begin() const
1011    {
1012        if (empty())
1013            return MatConstIterator_<_Tp>();
1014        CV_DbgAssert( elemSize() == sizeof(_Tp) );
1015        return MatConstIterator_<_Tp>((const Mat_<_Tp>*)this);
1016    }
1017
1018    template<typename _Tp> inline

(gdb) p elemSize()
$1 = 3
(gdb) p sizeof(_Tp)
$2 = 1

Thanks for your reply, it's very helpful to me. Since no error was reported, I thought color images were OK, but in fact only single-channel images can be used.

from opencv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.