MATLAB help 2D convolution

9 ビュー (過去 30 日間)
Yigit Goktas 2023 年 3 月 28 日
コメント済み: Walter Roberson 2023 年 3 月 28 日
I have a task to make a 2D convolution function that I have an image and a filter will be applied that should give the output result of image filtering in spatial domain. Also, during the edge detection(to handle boundaries) I have to use sobel and prewitt operator. I wrote a convolution code but I didn't quite get what is sobel and how to apply it. I got confused a bit and my code also gave error didn't get the reason and how to fix it?
The error I get:
Function padarray expected A (argument 1) to be numeric, logical or categorical for constant padding.
Error in Q4>my_convolution (line 15)
Error in Q4 (line 2)
outpu_image1 = my_convolution('Figure4.jpg',filter_1);
THE CODE:
filter_1 = [-1 0 1; -1 0 1; -1 0 1];
outpu_image1 = my_convolution('Figure4.jpg',filter_1);
function output_image = my_convolution(image, filter)
[im_height, im_width] = size(image);
[filter_height, filter_width] = size(filter);
output_image = zeros(im_height, im_width);
% Perform convolution
for i = 1:im_height
for j = 1:im_width
% Extract the local region of the padded image
% Compute the dot product between the local region and the filter
output_pixel = sum(sum(local_region .* filter));
% Assign the output pixel value to the output image
output_image(i, j) = output_pixel;
end
end
end

サインインしてコメントする。

回答 (2 件)

Walter Roberson 2023 年 3 月 28 日
outpu_image1 = my_convolution('Figure4.jpg',filter_1);
You are passing in the character vector 'Figure4.jpg' not the content of the image.
function output_image = my_convolution(image, filter)
We recommend against naming a variable image as image is one of the important graphics functions; people are likely to get confused.
2 件のコメントなしを表示なしを非表示
Yigit Goktas 2023 年 3 月 28 日
I changed it as
filter_1 = [-1 0 1; -1 0 1; -1 0 1];
output_image1 = my_convolution(image1,filter_1);
Then another error occured:
Error using .*
Integers can only be combined with integers of the same class, or scalar doubles.
Error in Q4>my_convolution (line 27)
output_pixel = sum(sum(local_region .* filter));
Error in Q4 (line 3)
output_image1 = my_convolution(image1,filter_1);
Walter Roberson 2023 年 3 月 28 日
Pass in double(image1)

サインインしてコメントする。

Image Analyst 2023 年 3 月 28 日
Try this:
function output_image = my_convolution(image1, filter)
output_image = GMag;

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeObject Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by