2

matlab で一連の 'tif' 画像の輝度成分を取得しようとしています。コードは次のとおりです。

function [defaultImages] = readImgLum(nFiles) 
% readImgLum reads a specified number of images in 'tif' format
% and retrieves the luminance component
narginchk(1, 1);
defaultImages = cell(nFiles, 1);                % store all images in a vector

for i = 1 : nFiles
    imagePreffix = int2str(i);
    imageFullName = strcat(imagePreffix, '.tif');
    image = imread(imageFullName);
    imageYCbCr = rgb2ycbcr(image);    
    defaultImages{i} = squeeze(imageYCbCr(:,:,1));
end

輝度成分を正しく抽出できていますか?

4

1 に答える 1

3

As the comments have stated, there is no need for squeeze. This code also looks fine to me. However, if you want to skip computing all components of YCbCr just to extract the luminance, use the SMPTE / PAL standard for calculating luminance instead. This is actually done in rgb2gray in MATLAB if you want to look up the source.

In any case, assuming your images are unsigned 8-bit integer:

image = double(image); 
defaultImages{i} = uint8(0.299*image(:,:,1) + 0.587*image(:,:,2) + 0.114*image(:,:,3));

BTW, image is a built-in command in MATLAB. It takes in any matrix, and visualizes it as an image in a new figure. I highly suggest you use another variable to store your temporary image as you may be calling further code later on that requires image as a function.

于 2014-08-26T17:56:35.023 に答える