I want to loop reading in several images. and then perform analysis on those images.

조회 수: 3 (최근 30일)
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)

답변 (1개)

Paul Hoffrichter
Paul Hoffrichter 2020년 12월 4일
편집: Paul Hoffrichter 2020년 12월 4일
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
Image Analyst
Image Analyst 2020년 12월 4일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by