- Let's say you start with the videos saved as individual image sequences (.jpg) in a folder. One folder per experiment, 400 images per folder.
- Read the images in the folder.
Multiple ROI's in a sequence/batch of images, pulling the data to a new array
11 views (last 30 days)
Show older comments
Good afternoon,
I am new to Matlab and am trying to do image analysis on large batches of JPEG or CSV files. I am able to import them into matlab from either format, but am having trouble writing a code that will allow me to set the ROI's on the first image in the sequence, and then use these ROI's to calculate the max, mean, min, and stdev values for each ROI and each subsequent image. I have to do this on multiple IR .seq files (we convert to jpeg or csv and import to matlab) but each video file has roughly 400 frames. Seq format doesnt seem to work with matlab so I think I have to import as a series of JPEG's and then run the analysis from there. Any tips or tricks would be great, I apologize as I don't know if I am using the write termonolgy either.
My ultimate goal is to create a plot showing the max, min and mean data vs time or frame (image number) for multiple objects in the batch of images. The objects could be moving at bit (video of worms) but my thinking is to create a mask to seperate the object I want (there is a large gradient within the ROI's that should allow me to use thresholding 4-5 sigma above background values to eliminate the noise and isolate the object). This needs to be repeatable for all the videos we have (a few hundred).
Any assistance would be greatly appreciated, even if its just links to the correct information. I am a bit overwhelmed as I am teaching myself at the moment. I know from my expeirence with coding in excel, there are multiple ways to accomplish the same goal, some ways are more efficient computing process wise which is why I thought to ask the experts. Thank you so much!
0 Comments
Answers (1)
Antoni Garcia-Herreros
on 15 May 2023
Hello Kegan,
If you don't provide any raw data is hard to come up with a specific solution, but the code structure could be something like this:
inputfoler='C/Docs/Experiment/Video_1/'
dir_images=dir(fullfile(inputfolder,'*.jpg')); % dir_images will contain a structure with all the .jpg images in your folder
3. Initialize the variables you want to study, select the ROI and loop through the images
MAX=zeros(size(dir_images,1),1);
MIN=MAX;STD=MAX;MEAN=MAX;
I=imread(fullfile(dir_images(i).folder,dir_images(i).name)); % Read the first image to use it for extracting the ROI
ROI=imrect;
l=floor(ROI.getPosition);
py=l(1); px=l(2); ly=l(3); lx=l(4) % Postion of the ROI rectangle
ROI=I(px:px+lx,py:py+ly,:);
%imshow(ROI) % Show ROI image
MAX(1)=max(ROI(:)); MIN(1)=min(ROI(:)); MEAN(1)=mean(ROI(:)); STD(1)=std(ROI(:));
for i=2:size(dir_images,1) % Loop through the images
I=imread(fullfile(dir_images(i).folder,dir_images(i).name));
ROI=I(px:px+lx,py:py+ly,:);
% Whatever process or object recognition code would go here
MAX(1)=max(ROI(:)); MIN(1)=min(ROI(:)); MEAN(1)=mean(ROI(:)); STD(1)=std(ROI(:));
end
% Plot your variables MAX, MIN, MEAN ,STD
plot(MAX)
You can continue from here by adding the object recognition, mask, filter, ...
Hope this helps
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!