Comments (2)
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.
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
requestsarray of images
source, notsingle image
. https://docs.opencv.org/4.x/d1/d79/group__photo__denoise.html#ga7602ed5ae17b7de40152b922227c4e4fvoid 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. Thisarray 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 indenoise_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)
- Is it possible to raise cmake_minimum_version in opencv 5.0? HOT 2
- get a classifier cascade parameters from original Cascase XML file
- when create new Mat with multi-channels(i.e., 8) with the particular value(i.e. 0.9), it will raise error (error: (-215:Assertion failed) cn <= 4 in function 'scalarToRawData') HOT 3
- Layer::finalize doc
- QRCodeEncoder segfault HOT 1
- dnn::Layer::allocate method does not exist anymore in doc
- "LNK2001 unresolved symbol" Erros about "cv::" Classes and Methods When Building a C++ Project with OpenCV and CUDA HOT 2
- Switch to FindPython3 in CMake (policy 0148) HOT 2
- [MSVC] opencv failed to run test Imgproc_EMD on x86 mode HOT 3
- Xcode fails to install app which uses OpenCV XCframework HOT 1
- Small differences in findChessboardCorners between aarch64 and amd64. HOT 2
- AttributeError: module 'cv2.dnn' has no attribute 'DictValue' HOT 1
- Support for lowpass/anti-alias enabled resizing operations to support preprocessing operations for models trained with torchvision HOT 1
- Unicode character in comment cause a warning(maybe an error) in MSVC
- Compilation of opencv.js fails with last version of Emscripten toolchain.
- Replacing the Lena image from the documentation HOT 2
- Problem with video time varying depending on brightness HOT 2
- Signed distance field HOT 1
- remap to dst array in python HOT 2
- Compiling with CUDA 11.8 breaks PyTorch convolution HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from opencv.