Multiple ROI's in a sequence/batch of images, pulling the data to a new array

15 views (last 30 days)
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!

Answers (1)

Antoni Garcia-Herreros
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:
  1. 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.
  2. Read the images in the folder.
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
  1 Comment
Kegan
Kegan on 23 May 2023
Here are two examples of the files I have which contain IR thermal imaging data. We can export the video files into images or csv (been going with jpgs, video original format which is .seq). I can batch load them into image processor but when I try to write a function to allow me to draw multiple ROI's and have them continue on the sequential frames, I can't seem to figure it out. I have also tried uploading the images into a workspace but it gives me an error that I have too many variables.
Thank you for your help, I am new to matlab and every process I try has some issue. I am still learning the language and keep watching tutorials and trying new code but have not been successful. I was hoping to use batch upload and then create a function to define the 8 ROI's on the first image and then pull that data from each ROI and each subsequent image into an array. Ultimate goal is to get max,min,mean temp vs time for each ROI over the duration of the video or image files.
Thank you again for your help!
Sincerely,
Kegan

Sign in to comment.

Categories

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

Products


Release

R2013b

Community Treasure Hunt

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

Start Hunting!