Extract RGB values of multiple images

조회 수: 2 (최근 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 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