Effacer les filtres
Effacer les filtres

What is the meaning of if (ndims(a)==2 | (a(:,:,1)==a(:,:,2) & a(:,:,2)==a(:,:,3))) this line?

2 vues (au cours des 30 derniers jours)
Shaila parvin
Shaila parvin le 28 Mai 2013
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 commentaire
Matt Kindig
Matt Kindig le 28 Mai 2013
Modifié(e) : Matt Kindig le 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.

Connectez-vous pour commenter.

Réponses (0)

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by