필터 지우기
필터 지우기

how to store rgb value of multiple images in matlab?

조회 수: 5 (최근 30일)
Raman kumar
Raman kumar 2015년 10월 19일
댓글: Image Analyst 2021년 8월 13일
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
suman jain
suman jain 2018년 12월 27일
Thanks.. it was useful
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