What is the meaning of if (ndims(a)==2 | (a(:,:,1)==a(:,:,2) & a(:,:,2)==a(:,:,3))) this line?
1 回表示 (過去 30 日間)
古いコメントを表示
My code is
clc
clear all
close all
dirpath = 'E:\4-1\image-thesis\implementation\shaila\';
f=dir(fullfile(dirpath,'*.jpg'));
f = f(arrayfun(@(x) x.name(1), f) ~= '.');
for i=1:length(f)
a=imread(strcat(dirpath,f(i).name));
if (ndims(a)==2 | (a(:,:,1)==a(:,:,2) & a(:,:,2)==a(:,:,3)))
%if (ndims(a)==2)
figure;imshow(a)
end
end
What is the meaning of if (ndims(a)==2 | (a(:,:,1)==a(:,:,2) & a(:,:,2)==a(:,:,3))) this line?
1 件のコメント
Matt Kindig
2013 年 5 月 28 日
編集済み: Matt Kindig
2013 年 5 月 28 日
The 'if' statement has the following logic:
1. If the number of dimensions of the image is 2, then imshow() the image.
2. If the number of dimensions is not 2, but all three "planes" of the image (i.e., the values in the third dimension) are all the same, imshow() it.
Basically, this code is reading images (with imread()), and, if a) the image is an indexed image, or b) the image is an RGB image with R, G, and B all the same (which occurs for a grayscale image), then display it using imshow(). Otherwise, skip it.
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Read, Write, and Modify Image についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!