Problem with a function using rgb2ycbcr

4 ビュー (過去 30 日間)
Brunna Albuquerque
Brunna Albuquerque 2013 年 6 月 11 日
編集済み: sanidhyak 2025 年 2 月 3 日
I am trying to do a function using rgb2ycbcr. It converts the image, then shows it up and saves it, but when I call the function, this error appears:
"Subscript indices must either be real positive integers or logicals."
Here's my code:
function x = rgb2yuv( x )
x = rgb2ycbcr(x)
imshow(x)
imwrite(x, 'C:\Users\aaaa\Documents\PDI\Atividade1\imagens\x_rgb2yuv.jpg', 'jpg')
end
What am I doing wrong?

回答 (1 件)

sanidhyak
sanidhyak 2025 年 2 月 3 日
編集済み: sanidhyak 2025 年 2 月 3 日
Hi Brunna,
I too encountered the same issue. This issue arises because the "rgb2ycbcr" function expects the input to be a valid numeric array representing an RGB image. Kindly refer to the below case as an example:
RGB = imread("board.tif");
YCBCR = rgb2ycbcr(RGB);
Ensure that RGB must be from one of the following formats:
  • A c-by-3 colormap, where each row specifies an RGB color value
  • An m-by-n-by-3 image matrix
So, to resolve this issue, you need to modify your function as follows:
function x = rgb2yuv(x)
x = imread(x); % Read the image first
x = rgb2ycbcr(x); % Convert to YCbCr
imshow(x); % Display the converted image
imwrite(x, 'C:/Users/aaaa/Documents/PDI/Atividade1/imagens/x_rgb2yuv.jpg', 'jpg'); % Save the output
end
This would ensure that the image is properly read before being processed.
For further reference, kindly refer to the MATLAB documentation below:

カテゴリ

Help Center および File ExchangeRead, 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