Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8478427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:44:35+00:00 2026-06-10T18:44:35+00:00

I would like to take two images and convolve them together in Matlab using

  • 0

I would like to take two images and convolve them together in Matlab using the 2D FFT without recourse to the conv2 function. However, I am uncertain with respect to how the matrices should be properly padded and prepared for the convolution.

The mathematical operation is the following:

A * B = C

In the above, * is the convolution operator (Wikipedia link).

The following Matlab program shows the difference between padding and not padding the matrices. I suspect that not padding the matrices results in a circular convolution, but I would like to perform a linear convolution without aliasing.

If I do pad the two matrices, then how do I truncate the output of the convolution so that C is the same size as A and B?

A = rgb2gray(im2double(imread('1.png'))); % input A
B = rgb2gray(im2double(imread('2.png'))); % kernel B

figure;
imagesc(A); colormap gray;
title ('A')

figure;
imagesc(B); colormap gray;
title ('B')

[m,n] = size(A);
mm = 2*m - 1;
nn = 2*n - 1;

C = (ifft2(fft2(A,mm,nn).* fft2(B,mm,nn)));

figure;
imagesc(C); colormap gray;
title ('C with padding')

C0 = (ifft2(fft2(A).* fft2(B)));

figure;
imagesc(C0); colormap gray;
title ('C without padding')

Here is the output of the program:

A
B
C
C0

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:44:37+00:00Added an answer on June 10, 2026 at 6:44 pm

    Without padding the result will be equivalent to circular convolution as you point out. For linear convolution, in convolving 2 images (2D signals) A*B the full output will be of size Ma+Mb-1 x Na+Nb-1, where Ma x Na, Mb x Nb the sizes of images A and B resp.

    After padding to the expected size, multiplying and transforming back, via ifft2, you can keep the central part of the resulting image (usually corresponding to the largest one of A and B).

    A = double(imread('cameraman.tif'))./255; % image
    B = fspecial('gaussian', [15 15], 2); % some 2D filter function
    
    [m,n] = size(A);
    [mb,nb] = size(B); 
    % output size 
    mm = m + mb - 1;
    nn = n + nb - 1;
    
    % pad, multiply and transform back
    C = ifft2(fft2(A,mm,nn).* fft2(B,mm,nn));
    
    % padding constants (for output of size == size(A))
    padC_m = ceil((mb-1)./2);
    padC_n = ceil((nb-1)./2);
    
    % frequency-domain convolution result
    D = C(padC_m+1:m+padC_m, padC_n+1:n+padC_n); 
    figure; imshow(D,[]);
    

    Now, compare the above with doing spatial-domain convolution, using conv2D

     % space-domain convolution result
     F = conv2(A,B,'same');
     figure; imshow(F,[]);
    

    Results are visually the same, and total error between the two (due to rounding) on the order of e-10.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create a program that compares two images. It must take
I have two ICollection s of which I would like to take the union.
I would like to take the Roman Numeral value stored in the object and
I would like to take a string representation of a set and parse it.
I would like to take a field and replace all characters that are not
I would like to take a specific part of the last line of a
I would like to take the memory generated from my struct and push it
I would like to take the words of a sentence, if that word has
What I would like to take ownership of a hid device that may already
I'm working in python 2.6 and I would like to take gpmetisfile.txt.part.4 and return

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.