hy guys,
i would like to deconvolute a matrix but i didn't find a 2d deconvolution function , any idea how to do that without using fft or ifft?
thank you in advance
code:
clear all
clc
a=randi(2,3)
b=randi(2,3)
c=conv2(a,b)
% [d,r]=deconv2(c,a) this is what i would like to get
subplot(221)
img(a)
subplot(222)
img(b)
subplot(223)
img(c)
subplot(224)
img(d)

 Akzeptierte Antwort

Matt J
Matt J am 4 Feb. 2022

0 Stimmen

Using
a=randi(2,3);
b=randi(2,3)
b = 3×3
2 1 2 2 2 1 2 1 1
c=conv2(a,b);
M=func2mat(@(x) conv2(a,x), zeros(3));
b_recon=reshape(M\c(:), 3,3)
b_recon = 3×3
2.0000 1.0000 2.0000 2.0000 2.0000 1.0000 2.0000 1.0000 1.0000

14 Kommentare

Rabih Sokhen
Rabih Sokhen am 4 Feb. 2022
thank you alot !!!
hy Matt.
i still have one question plz.
suppose i have the following code
code:
clear all
clc
a=rand(10,3);
b=rand10,3); %b=conv2(a,c)
%suppose that b is already the convolution of the array "a" with an array "c"
% I would like to deconvulte " b " to re-obtain "a" and "c".
% usually "a" and "c" have the same size
M=func2mat(@(x) conv2(a,x), zeros(3));
c=reshape(M\b(:), 3,3);
subplot(131)
pcolora(a)
subplot(132)
pcolor(b)
subplot(1333)
pcolor(c)
% i obtained the followig erro :
Error using \
Matrix dimensions must agree.
Error in conv_et_deconv (line 69)
c=reshape(M\b(:), 3,3);
can you help me with this plz ?
Matt J
Matt J am 7 Feb. 2022
You are still using reshape() to create a 3x3 matrix, even though the result now has a different size.
Rabih Sokhen
Rabih Sokhen am 7 Feb. 2022
Bearbeitet: Rabih Sokhen am 7 Feb. 2022
Yes, I totally agree.
I'm stuck at this point and I didn't know how to solve it.
Can you tell me what to do or what to fix in the reshape to reobtain my array "a" and "c" plz ?
Thank you in advance
Matt J
Matt J am 7 Feb. 2022
If you have to ask, it means you haven't read the documentation for reshape(). Had you done so, you would find it really simple.
Rabih Sokhen
Rabih Sokhen am 7 Feb. 2022
I have read the document
I know that's X=reshape (Z, n, m) will reshape the array Z into n*m array called X, also it should that n*m = number of elements of A
However the error in my code is in the division, in M\b(:). I never used sparse before and it looks that's the dimension of M does not agree with b to be able to to the division
hope I am not mistaken with the analyse
Matt J
Matt J am 7 Feb. 2022
Bearbeitet: Matt J am 7 Feb. 2022
Yes, you're right. An additional problem is that the 2nd input to func2mat() is also the wrong size .
m=10; n=3; %expected dimensions of b
M=func2mat(@(x) conv2(a,x), zeros(m,n) );
c=reshape(M\b(:), m,n);
Rabih Sokhen
Rabih Sokhen am 8 Feb. 2022
i did try it but i still have a error
code:
clear all
clc
a=rand(10,3);
b=rand(10,3);
[m,n]=size(a);
M=func2mat(@(x) conv2(a,x), zeros(m,n) );
c=reshape(M\b(:), m,n);
error
Error using \
Matrix dimensions must agree.
a=rand(10,3);
b=rand(10,3)
b = 10×3
0.7691 0.1625 0.7079 0.1838 0.4012 0.9035 0.2503 0.1830 0.4700 0.1909 0.4764 0.8176 0.2930 0.3865 0.2518 0.8353 0.4449 0.4590 0.1506 0.4136 0.5710 0.0331 0.2194 0.1108 0.3300 0.9208 0.1941 0.8414 0.2407 0.8796
c=conv2(a,b);
[m,n]=size(a);
M=func2mat(@(x) conv2(a,x), zeros(m,n) );
b=reshape(M\c(:), m,n)
b = 10×3
0.7691 0.1625 0.7079 0.1838 0.4012 0.9035 0.2503 0.1830 0.4700 0.1909 0.4764 0.8176 0.2930 0.3865 0.2518 0.8353 0.4449 0.4590 0.1506 0.4136 0.5710 0.0331 0.2194 0.1108 0.3300 0.9208 0.1941 0.8414 0.2407 0.8796
Rabih Sokhen
Rabih Sokhen am 8 Feb. 2022
Hey Matt,
hope you are doing good today.
Thank you for your answer and I really appreciate your help.
concerning the code :
suppose that's i have "a" and "b"
a=rand(3,5)
b=rand(3,5)
and i am concidering that's b is already the 2d convloution of "a" with a array "c" and i don't have "c" .
how can i find "c" ?
thank you in advance
Matt J
Matt J am 8 Feb. 2022
Bearbeitet: Matt J am 8 Feb. 2022
For the matrix sizes you have shown, b cannot be the result of a convolution of a and another matrix c. The result of a convolution has to be larger than either a or c. In particular, it must satisfy
size(b)=size(a)+size(c)-1;
I have changed the size of the convolution array.
I considered nowthat "c" is the convolution array and the of size(c) =2*n-1 2*m-1 and c=conv2 (a, b)
Suppose I have "a" and "c"
I did deconvolute "c" with "a" to obtain "b" by using your method.
However, I tried to verify my answer by reconvoluting "b" with "a" and I expected to obtain "c", but I obtained a different result than "c"
did i wrote something wrong ?
thank you in advance
code:
clear all
clc
n=3;
m=5;
a=rand(n,m);
c=rand(2*n-1,2*m-1); %c is already the convolution of a with b
M_a=func2mat(@(x) conv2(a,x), zeros(n,m));
b=reshape(M_a\c(:), n,m);
subplot(221)
img(a)
title('a')
subplot(222)
img(c)
title('c')
subplot(223)
img(b)
title('b=deconv2(c,a)')
subplot(224)
cc=conv2(b,a);
img(cc)
title('cc=conv2(b,a)')
Matt J
Matt J am 8 Feb. 2022
Bearbeitet: Matt J am 8 Feb. 2022
By generating c in a completely random manner c=rand(2*n-1,2*m-1), there is no gaurantee that it is the result of a convolution. The solution you are getting with M_a\c(:) is, however, the best estimate for b in the least squares sense.
Rabih Sokhen
Rabih Sokhen am 8 Feb. 2022
I really appreciate your help.
Thanks you a lot

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Matt J
Matt J am 8 Feb. 2022
Bearbeitet: Matt J am 8 Feb. 2022

1 Stimme

I would like to deconvolute a matrix but i didn't find a 2d deconvolution function.
See deconvreg(), deconvlucy(), deconvblind(), and deconvwnr().
Walter Roberson
Walter Roberson am 8 Feb. 2022
Bearbeitet: Walter Roberson am 8 Feb. 2022

0 Stimmen

https://www.mathworks.com/matlabcentral/answers/1620780-convolve-text-with-image#comment_1953810 shows an implementation for the case of it really only being 1d convolution

2 Kommentare

hy Walter , hope your doing well
I have seen your link, I don't have a strong background in Matlab, I have understood the global idea of it but not the entire script.
Matt already helped me alot and he did wrote me a great function, however i still have same error wen i try to deconvolute a array as in the folowing exemlple:
can you modify my code if that's possible?
code:
clear all
clc
a=rand(10,3);
b=rand(10,3);
[m,n]=size(a);
M=func2mat(@(x) conv2(a,x), zeros(m,n) );
c=reshape(M\b(:), m,n);
error
Error using \
Matrix dimensions must agree.
Walter Roberson
Walter Roberson am 8 Feb. 2022
That is Matt's code, not mine; explanation should come from him.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by