Extract RGB values of multiple images

4 ビュー (過去 30 日間)
Danah Abdulghani A Aljishi
Danah Abdulghani A Aljishi 2022 年 12 月 9 日
コメント済み: Image Analyst 2022 年 12 月 13 日
Hello,
I have 300 images that I would like to extract the rgb values of each image individually. How can I do that?
Thanks

採用された回答

Image Analyst
Image Analyst 2022 年 12 月 9 日
Use imread to get the RGB values of each image
for k = 1 : 300
filename = whatever
rgbValues = imread(filename);
end
  7 件のコメント
DGM
DGM 2022 年 12 月 13 日
I don't know what other program has problems separating color channels, but there are a lot of things I don't know. If all you truly need to do is split the images and save the image channels independently, then I don't see why you can't do that in the loop. You'll just have to use imwrite() to write each channel to an appropriate filename and directory.
I will point out that it would be a generally bad idea to use JPG as the output file format. Use PNG if data integrity is of any concern.
Image Analyst
Image Analyst 2022 年 12 月 13 日
Then you'll need to use imwrite instead of stuffing them all into a cell array, which your other program won't understand.
myFolder = '......./Pictures/Fine - 1';
filePattern = fullfile(myFolder, '*.jpg');
theFiles = dir(filePattern);
n = length(theFiles);
R = cell(n,1);
G = cell(n,1);
B = cell(n,1);
for k = 1 : n
baseFileName = theFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
rgbImage = imread(fullFileName);
[r, g, b] = imsplit(rgbImage);
% Get file parts
[folder, baseFileNameNoExt, ext] = fileparts(fullFileName);
% Save images to disk for the other program that needs them.
% Save red channel.
outputBaseFileName = sprintf('%s_R.png', baseFileNameNoExt);
outputFullFileName = fullfile(folder, outputBaseFileName);
imwrite(r, outputFullFileName);
% Save green channel.
outputBaseFileName = sprintf('%s_G.png', baseFileNameNoExt);
outputFullFileName = fullfile(folder, outputBaseFileName);
imwrite(g, outputFullFileName);
% Save blue channel.
outputBaseFileName = sprintf('%s_R.png', baseFileNameNoExt);
outputFullFileName = fullfile(folder, outputBaseFileName);
imwrite(b, outputFullFileName);
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Processing and Computer Vision についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by