What is the meaning of if (ndims(a)==2 | (a(:,:,1)==a(:,:,2) & a(:,:,2)==a(:,:,3))) this line?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Matt Kindig
am 28 Mai 2013
Bearbeitet: Matt Kindig
am 28 Mai 2013
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.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Read, Write, and Modify Image finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!