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
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 CenterFile 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!

Translated by