Extract RGB values of multiple images

2 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Image 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