Extract RGB values of multiple images

2 Ansichten (letzte 30 Tage)
Danah Abdulghani A Aljishi
Kommentiert: Image Analyst am 13 Dez. 2022
Hello,
I have 300 images that I would like to extract the rgb values of each image individually. How can I do that?
Thanks

Akzeptierte Antwort

Image Analyst
Image Analyst am 9 Dez. 2022
Use imread to get the RGB values of each image
for k = 1 : 300
filename = whatever
rgbValues = imread(filename);
end
  7 Kommentare
DGM
DGM am 13 Dez. 2022
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 am 13 Dez. 2022
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Image Processing and Computer Vision finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by