MEAN OF IMAGE IN MATLAB

3 views (last 30 days)
Aybüke Ceren Duran
Aybüke Ceren Duran on 24 Apr 2019
Edited: Rik on 24 Apr 2019
format compact
%Firstly, I converted all the images in the vector form.
whereImagesReside = 'lfwdataset';
%dir function will return the images in a structure array.
listOfImages= dir(fullfile(whereImagesReside, '*.pgm'));
%0x1 structure array is created
data = cell(size(listOfImages));
%pmg files are stored in column matrix columnMatrix in the end of the loop
%below
for k=1:numel(listOfImages)
data{k}=imread(fullfile(whereImagesReside, listOfImages(k).name));
%data{k}=im2double(rgb2gray(data{k}));
[r,c] = size(data{k}); % get number of rows and columns in image
%columnMatrix(:,k)=data(:);
V{k}=data(:);
end
%So, data cell array holds the intensity of each gray image.
%intensity = cellfun(@imshow, data, 'uniform', 0);
%disp(intensity);
How can I take the mean of image?
  1 Comment
Rik
Rik on 24 Apr 2019
This time I edited your question for you. Next time, please use the tools explained on this page to make your question more readable.

Sign in to comment.

Answers (1)

Rik
Rik on 24 Apr 2019
Edited: Rik on 24 Apr 2019
If your list of images is a 0x1 struct, then the files are not found. Once you solve that issue, you can use the code below to find the intensity. Note that storing the full image may require a lot of memory, so you may consider skipping that.
data = cell(size(listOfImages));
intensity = zeros(size(listOfImages));
for k=1:numel(listOfImages)
data{k}=imread(fullfile(whereImagesReside, listOfImages(k).name));
intensity(k)=mean(data{k}(:));%mean will convert your data type to double
end

Categories

Find more on Convert Image Type in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!