how to store rgb value of multiple images in matlab?

3 次查看(过去 30 天)
I have 208 images in the folder I want the RGB values of those images present in the folder and to store them ? i was trying with cell function but not able to use properly if someone has better solution?
  2 个评论
varuna watwe
varuna watwe 2021-8-13
I have 20 images. I am successful in reading all images from folder containing them. What I want is, want RGB values of each image separately in different variables to process them further. Please help.
Image Analyst
Image Analyst 2021-8-13
@varuna watwe, you should easily be able to adapt my code below. If you can't, then post your attempt in a new question (not here).

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2015-10-19
cell() is not the right function. When you say you want "RGB values of those images", what do you mean by that? Do you want the mean RGB values of each image? Because with an image of say, a megapixel, you will have a million RGB values in your array (after you call imread). So you already have ALL the RGB values, but did you want any particular or special RGB values, like those in some region of the image?
To process all 208 images, see the code in the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F. And make sure you don't use image for the name of any of your variables.
  2 个评论
Raman kumar
Raman kumar 2015-10-20
编辑:Image Analyst 2018-12-27
Actually the thing is I want to perform skin pixel detection on those 208 images and the conditions are like this :
(R,G,B) is classified as :
R>95&G>40&B>20 & max{R,G,B}-min{R,G,B}>15 & |R-G|>20 & R>G & R>B
on single image, I am able, but to apply but on a folder I am not getting how to do. I have find function for that whole conditions when applied on single image.
Image Analyst
Image Analyst 2018-12-27
Raman:
Try this:
% User wants this segmentation:
% R>95&G>40&B>20 & max{R,G,B}-min{R,G,B}>15 & |R-G|>20 & R>G & R>B
% Specify the folder where the files live.
myFolder = pwd; % or 'C:\Users\yourUserName\Documents\My Pictures';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isfolder(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.jpg'); % Change to whatever pattern you need.
theFiles = dir(filePattern)
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
rgbImage = imread(fullFileName);
if ndims(rgbImage) < 3
continue; % Skip gray scale and indexed images.
end
subplot(1, 2, 1);
imshow(rgbImage); % Display image.
caption = sprintf('Original: %s', baseFileName);
title(caption, 'FontSize', 20, 'Interpreter', 'none');
% Extract the individual red, green, and blue color channels.
R = rgbImage(:, :, 1);
G = rgbImage(:, :, 2);
B = rgbImage(:, :, 3);
% Create the mask image.
maxMinusMinImage = max(rgbImage, [], 3) - min(rgbImage, [], 3);
mask = R>95 & G>40 & B>20 & maxMinusMinImage > 15 & ...
abs(double(R-G)) > 20 & (R > G) & (R>B);
subplot(1, 2, 2);
imshow(mask); % Display image.
caption = sprintf('Mask for: %s', baseFileName);
title(caption, 'FontSize', 20, 'Interpreter', 'none');
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0.1, 1, 0.9]);
drawnow; % Force display to update immediately.
end

请先登录,再进行评论。

更多回答(1 个)

Martin Schätz
Martin Schätz 2015-10-19
Hi, you can put each of your images (array [sizex,sizey,3]) in a cell. It is created with {}. So if you have some loop where you load images, you can do it like this:
for i=1:N
images{i}=imread(image);
end
  3 个评论
Image Analyst
Image Analyst 2018-12-27
Not really useful. No need to put into a cell array at all. See better code below:
% User wants this segmentation:
% R>95&G>40&B>20 & max{R,G,B}-min{R,G,B}>15 & |R-G|>20 & R>G & R>B
% Specify the folder where the files live.
myFolder = pwd; % or 'C:\Users\yourUserName\Documents\My Pictures';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isfolder(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.jpg'); % Change to whatever pattern you need.
theFiles = dir(filePattern)
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
rgbImage = imread(fullFileName);
if ndims(rgbImage) < 3
continue; % Skip gray scale and indexed images.
end
subplot(1, 2, 1);
imshow(rgbImage); % Display image.
caption = sprintf('Original: %s', baseFileName);
title(caption, 'FontSize', 20, 'Interpreter', 'none');
% Extract the individual red, green, and blue color channels.
R = rgbImage(:, :, 1);
G = rgbImage(:, :, 2);
B = rgbImage(:, :, 3);
% Create the mask image.
maxMinusMinImage = max(rgbImage, [], 3) - min(rgbImage, [], 3);
mask = R>95 & G>40 & B>20 & maxMinusMinImage > 15 & ...
abs(double(R-G)) > 20 & (R > G) & (R>B);
subplot(1, 2, 2);
imshow(mask); % Display image.
caption = sprintf('Mask for: %s', baseFileName);
title(caption, 'FontSize', 20, 'Interpreter', 'none');
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0.1, 1, 0.9]);
drawnow; % Force display to update immediately.
end

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by