how to adjust the size of the imported image to use it in (rgb2gray()) ?

1 回表示 (過去 30 日間)
Mohamed Ahmed
Mohamed Ahmed 2020 年 11 月 17 日
コメント済み: Mohamed Ahmed 2020 年 11 月 20 日
Hi
I = imread(fname);I'm writing a code for image dataset that has 1 main folder and 10 subfolders within, and I want to apply fourier transform to all images in these folders,
I wrote this code below. It gives me an error (MAP must be a m x 3 array) in (I = rgb2gray(I);) because of the size of (I).
I = imread(fname);
how do I make I = imread(fname) ; into the size that I can use in rgb2gray ?
can you please help me with this ?
code:
clc;
clear all;
img = dir('C:\AppliedProj\Train\0\*.jpg');
Images_num = length(img);
for i = 1:Images_num
fname = strcat('C:\AppliedProj\Train\0\', img(i).name);
I = imread(fname);
I = rgb2gray(I);
%Get Fourier Transform of an image
F = fft2(I);
% Fourier transform of an image
S = abs(F);
%get the centered spectrum
Fsh = fftshift(F);
%apply log transform
S2 = log(1+abs(Fsh));
%reconstruct the Image
F = ifftshift(Fsh);
f = ifft2(F);
path = strcat('C:\AppliedProj\New\0\', img(i).name);
imwrite(f,path);
end
Best regards

採用された回答

Shashank Gupta
Shashank Gupta 2020 年 11 月 20 日
Hi Ahmed,
The error "MAP must be a m x 3 array." is generally occurs when one try to pass one channel image(possibly gray image) to
"rgb2gray" function. these function can take two types of input either one pass an RGB image or a colour map. What I understand from your code is, you intent to pass an image and the error is popping up because the image is itself Gray and it doesn't need to pass through rgb2gray function. Suggestion is to just remove or comment out that line of code and it should work for you.
Cheers

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by