Error using reshape syntax

9 visualizzazioni (ultimi 30 giorni)
Wildan
Wildan il 4 Apr 2019
Risposto: Walter Roberson il 4 Apr 2019
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

Risposta accettata

Walter Roberson
Walter Roberson il 4 Apr 2019
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.

Più risposte (0)

Categorie

Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by