Reading and displaying images from a Directory.

2 ビュー (過去 30 日間)
Nadia
Nadia 2013 年 4 月 23 日
Hi, I have to read images from a directory and then according to whether the number of images are even or odd, I need to display some from of them. If even images then I need to display color and gray version. If odd I need to display to gray and histogram version. I have my code, but when I run it all it does is show the m-file name. PLEASE HELP!!!! Here's the code:
jpgImages = dir('Pictures.jpg');
numImages = length(jpgImages);
if mod(numImages, 2) == 0
for i = 1:numImages
filename = strcat('Pictures',jpgImages(i).name);
A = imread(filename);
B = rgb2gray(A);
subplot(1,2,1), imshow(A)
subplot(1,2,2), imshow(B)
end
else
for i = 1:numImages
figure
subplot(1,3,1), imshow(B)
subplot(1,3,2), imhist(B)
end
end
THANKS!

採用された回答

Walter Roberson
Walter Roberson 2013 年 4 月 23 日
Your code does not load any images or define "B" when the number of images is odd.
dir('Pictures.jpg') is going to only find (at most) one file "Pictures.jpg", unless "Pictures.jpg" happens to be the name of a directory. If it is the name of a directory then (A) that is confusing; and (B) remember to eliminate "." and ".." from the list.
Your line
filename = strcat('Pictures',jpgImages(i).name);
does not appear to account for the directory separator. Consider using fullfile()

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by