Error using reshape syntax

9 次查看(过去 30 天)
I'm new in Matlab. I want to reduce the size of the vector magnitude to smaller so that later I can use it for the KNN classification. So I try use 'reshape' to reduce the vector column size to 100
Error using reshape
To RESHAPE the number of elements must not change.
Error in Gabor2 (line 25)
rs = reshape(mag,1,250*250);
Here is my code..
%Pelatihan (Training)
folder_citra = 'data latih';
nama_citra = dir(fullfile(folder_citra, '*.jpg'));
jumlah_citra = numel(nama_citra);
for n = 1:jumlah_citra
% Membaca citra
Img = imread(fullfile(folder_citra, nama_citra(n).name));
% Resize citra
Img_resize = imresize(Img, [250 250]);
% Konversi citra RGB menjadi Grayscale
Img_gray = rgb2gray(Img_resize);
% Ekstraksi Ciri Tekstur Filter Gabor
wavelength = 4;
orientation = 90;
[mag,phase] = imgaborfilt(gray, wavelength, orientation);
rs = reshape(mag,1,250*250);
mag_kecil = imresize(mag,1/25);
training = reshape(mag_kecil,1,100);
end

采纳的回答

Walter Roberson
Walter Roberson 2019-4-4
reshape() can never be used to make an array smaller. It can only be used to change how a block of memory is indexed, with the number of elements having to stay the same.
You might be able to use resample() for your purposes.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by