bounjours a tous , alors j'ai commence de trvaille avec matlab j'ai esseye de faire le produit de convolusion entre une image et un filtre gaussian avec la fonction conv2 mais je suis bloqué a cause de ca voila l'erreur:N-D arrays are not supported.

2 次查看(过去 30 天)
sigma1 = 1.9;
sigma2 =2.8;
img=imread('image.jpg');
hsize = [3,3];
h1 = fspecial('gaussian', hsize, sigma1);
h2 = fspecial('gaussian', hsize, sigma2);
% [a,b]=size(img);
% m1=max([a+3-1,a,3]);
% n1=max([b+3-1,b]);
% im1=cell(m1,n1);
im1=conv2(img,h1);
im2=conv2(img,h2);

采纳的回答

Rik
Rik 2018-2-13
Next time, use the {}Code button to format your code.
You did img=imread('image.jpg');, which results in a 3D matrix (column,row,color). You need to reduce that to two dimension, e.g. with img=imread('image.jpg');img=mean(img,3);.
  5 个评论
Rik
Rik 2018-2-17
It looks like L2 and L1 are 2D matrices, while your assignment only works for a scalar. A bit later in your code you're using temp_D(:,:,j)=L2-L1; which should work here as well, although I don't know if that is what you mean.
amal abbbes
amal abbbes 2018-2-17
编辑:amal abbbes 2018-2-17
Here I want to created a single-line matrix and three columns with each box containing another matrix I want to stores the image in this sub matrix.so How I can solve the problem please

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2018-2-17
You need to convert from color to gray scale and then cast the image to single or double before sending in to conv2().
Try this:
clc;
fontSize = 15;
% Read in image.
rgbImage = imread('peppers.png');
% Display the image.
subplot(2, 3, 1);
imshow(rgbImage, []);
title('Original Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis on;
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(rgbImage);
% Convert to gray scale.
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
% grayImage = rgb2gray(rgbImage);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
grayImage = rgbImage(:, :, 1); % Take red channel.
else
grayImage = rgbImage; % It's already gray scale.
end
% Display the image.
subplot(2, 3, 2);
imshow(grayImage, []);
title('Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis on;
% Get the blur kernels.
sigma1 = 1.9;
sigma2 = 2.8;
windowSize = [3,3];
h1 = fspecial('gaussian', windowSize, sigma1);
h2 = fspecial('gaussian', windowSize, sigma2);
% Display the image.
subplot(2, 3, 3);
imshow(h1, []);
title('Blur Kernel 1 Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis on;
% Display the image.
subplot(2, 3, 4);
imshow(h2, []);
title('Blur Kernel 2 Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis on;
drawnow; % Force screen repaint right now.
% Blur the image.
im1 = conv2(double(grayImage), h1);
im2 = conv2(double(grayImage), h2);
% Display the image.
subplot(2, 3, 5);
imshow(im1, []);
title('Blurred Image 1', 'FontSize', fontSize, 'Interpreter', 'None');
axis on;
% Display the image.
subplot(2, 3, 6);
imshow(im2, []);
title('Blurred Image 2', 'FontSize', fontSize, 'Interpreter', 'None');
axis on;
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0.05, 1, 0.95]);
  3 个评论
Image Analyst
Image Analyst 2018-2-17
You forgot to attach img1.jpg. Also, there is an extra right bracket:
end
]
end
that I'm sure is causing problems. And in
temp_D(k,i,j)=L2-L1;
L2 and L1 are 2-D images and you're trying to stuff the difference of two images, which is itself another image, into a single element of a 3-D array. Why are you trying to do that? Maybe you should make temp_D a cell array if it's supposed to hold different sized arrays.
amal abbbes
amal abbbes 2018-2-17
it is as if Submatrix Nested in one each box of the matrice.I wants to create a matrix m (1, 3) which contains a single row and three columns and in each box of the matrix m, m (i, J) I want to create another m2 matrix of size (3.1) and then in Ach cell of the M2 matrix ,I want to store the image :pyramide de gaussaian how can i do it please

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Convolution 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by