MEAN OF IMAGE IN MATLAB
3 views (last 30 days)
Show older comments
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
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.
Answers (1)
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
0 Comments
See Also
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!