Borrar filtros
Borrar filtros

how to store rgb value of multiple images in matlab?

6 visualizaciones (últimos 30 días)
Raman kumar
Raman kumar el 19 de Oct. de 2015
Comentada: Image Analyst el 13 de Ag. de 2021
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 comentarios
varuna watwe
varuna watwe el 13 de Ag. de 2021
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 el 13 de Ag. de 2021
@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).

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 19 de Oct. de 2015
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 comentarios
Raman kumar
Raman kumar el 20 de Oct. de 2015
Editada: Image Analyst el 27 de Dic. de 2018
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 el 27 de Dic. de 2018
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

Iniciar sesión para comentar.

Más respuestas (1)

Martin Schätz
Martin Schätz el 19 de Oct. de 2015
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 comentarios
suman jain
suman jain el 27 de Dic. de 2018
Thanks.. it was useful
Image Analyst
Image Analyst el 27 de Dic. de 2018
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

Iniciar sesión para comentar.

Categorías

Más información sobre Images en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by