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 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
amal abbbes
el 13 de Feb. de 2018
Comentada: amal abbbes
el 17 de Feb. de 2018
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);
0 comentarios
Respuesta aceptada
Rik
el 13 de Feb. de 2018
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 comentarios
Rik
el 17 de Feb. de 2018
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.
Más respuestas (1)
Image Analyst
el 17 de Feb. de 2018
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 comentarios
Image Analyst
el 17 de Feb. de 2018
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.
Ver también
Categorías
Más información sobre Convolution en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!