MATLAB Convolution ('Conv') in MATLAB

AI Thread Summary
The discussion revolves around a user encountering errors while attempting to convolve an image with an impulse response in MATLAB. The user initially faces a "Subscripted assignment dimension mismatch" error and a message indicating that the inputs to the convolution function must be vectors. The issue stems from the image being a 3-dimensional matrix due to its RGB format, which is incompatible with the convolution operation. The user realizes that converting the image to grayscale is necessary but initially struggles with the output from the rgb2gray function, which results in an unexpected bright red color. Ultimately, the user resolves the problem and indicates that the issue can be closed.
mushiman
Messages
10
Reaction score
0
I have a problem/error that I believe is very simple, but I am unable to determine what the issue is nonetheless.

I am trying to convolute an image with an impulse response (IE, h = [1 2 3]), but I get incessant errors and I am unsure as to why. My code is:

Code:
A = double(imread('image.jpg'));
B = zeros(514);
h = [1 2 3];

for k = 1:512
    B(k,:) = conv[A(k,:),h];

I get the error "? Subscripted assignment dimension mismatch.", or alternatively, MATLAB returns "? Error using ==> conv, A and B must be vectors." if I attempt to zero-pad my impulse response (h), then insert my matrix values of 1, 2, and 3.

I'm sure that I am missing something very simple here, but I do not know what it is. At the moment, I am running this code in the terminal, although I don't believe that this is the cause of the problem.

Thank you to anyone who helps -- I'm banging my head against the desk.

Edit: Just a quick note... apparently I forgot to convert to grayscale, and for that reason this image was a 3-dimensional matrix, which doesn't fly in this situation. However, I am still unsure as to how to get it formatted properly, as rgb2gray does not give me the output that I was looking for (it converts the image into a bright red color).
 
Last edited:
Physics news on Phys.org
I figured out what the problem was; this can be closed/deleted.
 

Similar threads

Replies
4
Views
4K
Replies
32
Views
4K
Replies
4
Views
1K
Replies
7
Views
2K
Replies
5
Views
2K
Replies
5
Views
3K
Replies
4
Views
3K
Replies
1
Views
3K
Replies
5
Views
2K
Replies
3
Views
3K
Back
Top