I want to loop reading in several images. and then perform analysis on those images.
3 views (last 30 days)
Show older comments
At the moment I have a body of code that can read in all JPG images inside a file.
What I want to do is essentially take an average image of all the images that have been read in (by adding up all the seperate images matrix values) i can only do this manually at the minute (can't figure out how to loop),
Finally (The Most Important) plot a graph that shows how the value of the change of the sum image fluctuates over time, so for example image 1 is a dim image, image two is an extremely bright image, image 3 is a dim image - the graph should show a fluctuation from low to high to low again - I attempted this but received results in the RGB field - so it doesnt display correctly.
Here is my code below:
ImageFolder = 'H:\My Documents\Dissertation';
if ~isfolder(ImageFolder)
ErrorMessage = print('Error: The following folder does not exist: Please specify a new folder.', ImageFolder);
uiwait(warndlg(ErrorMessage));
ImageFolder = uigetdir();
if ImageFolder == 0
return;
end
end
FileType = fullfile(ImageFolder, '*.jpg');
TheImages = dir(FileType);
for k = 1:length(TheImages)
baseFileName = TheImages(k).name;
fullFileName = fullfile(TheImages(k).folder, baseFileName);
imageArray = imread(fullFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
imshow(imageArray);
drawnow;
end
OriginalImage = imread('Img000000.jpg');
SecondImage = imread('Img000001.jpg');
ThirdImage = imread('Img000002.jpg');
FourthImage = imread('Img000003.jpg');
FifthImage = imread('Img000004.jpg');
SixthImage = imread('Img000005.jpg');
SeventhImage = imread('Img000006.jpg');
Image8 = imread('Img000007.jpg');
Image9 = imread('Img000008.jpg');
sumImage = OriginalImage + SecondImage + ThirdImage + FourthImage + FifthImage + SixthImage + SeventhImage + Image8 + Image9;
for i = 2:length(TheImages)
rgbImage = imread(fullFileName);
end
meanImage = sumImage / length(TheImages);
imshow(sumImage)
plot(meanImage)
0 Comments
Answers (1)
Paul Hoffrichter
on 4 Dec 2020
Edited: Paul Hoffrichter
on 4 Dec 2020
sumImage = OriginalImage + SecondImage + ThirdImage + FourthImage + FifthImage + SixthImage + SeventhImage + Image8 + Image9;
You are adding up uint8 data types which is in the range 0..255. So you are truncating to 255. Look at the sumImage values. Most will likely be 255.
>> OriginalImage = imread('Img000000.jpg');
Change all the images like this:
OriginalImage = double( imread('Img000000.jpg') );
and the numbers will add up better.
1 Comment
Image Analyst
on 4 Dec 2020
And then
meanImage = sumImage / length(TheImages);
imshow(meanImage, []); % Use [] because it's outside the range of 0-1 and it's a floating point number, not a uint8
%plot(meanImage) % Do NOT call plot with images!
Not sure what the point of the for loop is if you're just going to overwrite the array inside the loop and then not even use it later because you read the 9 images individually.
See Also
Categories
Find more on Convert Image Type in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!