Convolution ('Conv') in MATLAB

  • Context: MATLAB 
  • Thread starter Thread starter mushiman
  • Start date Start date
  • Tags Tags
    Convolution Matlab
Click For Summary
SUMMARY

The discussion centers on the use of convolution in MATLAB for image processing, specifically using the 'conv' function with an impulse response defined as h = [1 2 3]. The user encountered errors related to dimension mismatches and vector requirements when attempting to convolute a 3-dimensional RGB image. The issue was resolved by converting the image to grayscale, although the user initially faced challenges with the output color after using the rgb2gray function.

PREREQUISITES
  • Understanding of MATLAB programming and syntax
  • Familiarity with image processing concepts, particularly convolution
  • Knowledge of MATLAB functions such as 'conv' and 'rgb2gray'
  • Basic understanding of matrix dimensions and operations in MATLAB
NEXT STEPS
  • Explore MATLAB's image processing toolbox for advanced convolution techniques
  • Learn about different image color spaces and their conversions in MATLAB
  • Research the implications of using 2D convolution on multi-dimensional arrays
  • Investigate the use of zero-padding in convolution operations in MATLAB
USEFUL FOR

This discussion is beneficial for MATLAB users, particularly those involved in image processing, computer vision, and anyone looking to understand convolution operations and their implementation in MATLAB.

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 ·
Replies
4
Views
4K
  • · Replies 32 ·
2
Replies
32
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
1
Views
3K