How can I extract the region of interest and its features of the highest moving energy/intensity area

The following is a part of images (video) that taken in an experiment
How can I only take into consideration the highest moving energy/intensity area that keeps moving and discard the rest of the image?
I mean I want only to extract the region of interest (the highest moving energy/intensity area) and its features?
I have multiple experiments (around 60000) and I want to do the same for all of them
Note: When you run it as a video you will notice the area
Note that the ROI alawys has more events (more density), this will help to avoid annotation process
load ('data.mat')
for i = 1:201
imshow(data(:,:,:,i),[]);
pause(0.001)
end

Answers (2)

The Computer Vision Toolbox has tracking functions in it. Look into them.

7 Comments

Thanks @Image Analyst, but I dont need to track all the moving objects, I want only the one with the highest desnsity/energy. Also, my object doesnt has wide range of motion.
Just segment out the object you want and call regionprops to get its centroid. Do it for all frames and log the centroids to a matrix.
It's a generic, general purpose demo of how to threshold an image to find blobs, and then measure things about the blobs, and extract certain blobs based on their areas or diameters.
This is one of the sample from series of images, I tired to do blobs detection as described in your tutorial but it didn't work with me, it didnt detect the whole hight dense area although I tired different thresholds
This is the image
My goal is to get only three area the ones the I colored, something similer to this
If you don't want the holes inside to be excluded (that is, you want them to be considered part of the contact area) you can use imfill
mask = grayImage > someThreshold;
mask = imfill(mask, 'holes');
% Take 3 largest blobs
mask = bwareafilt(mask, 3);
% Compute areas and centroid
props = regionprops(mask, 'Area', 'Centroid');
xy = vertcat(props.Centroid);
allAreas = [props.Area]
% Sort in order of increasing y value
[sortedY, sortOrder] = sort(xy(:, 2), 'ascend')
% Sort the areas the same way
allAreas = allAreas(sortOrder)
If you don't want interior holes considered as part of the area, we'll have to do additional operations.
@Image Analyst Thanks, could you please tell me what is the best way to choose the threshold
If you don't want interior holes considered as part of the area, we'll have to do additional operations.
Could you please suggest to me how can this be done? because I am not interested in the interior holes, (just to make sure, you meant by holes the inside black holes right?
Also, please clarify the purpose of calculating centroid, xy and areas
@Image Analyst when you have free time please reply to my questions. thanks

Sign in to comment.

Try this:
% Demo by Image Analyst
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
markerSize = 20;
%--------------------------------------------------------------------------------------------------------
% READ IN TEST IMAGE
folder = pwd;
baseFileName = "m's image.png";
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get size
[rows, columns, numberOfColorChannels] = size(grayImage)
% Convert to grayscale if it is not already.
if numberOfColorChannels == 3
grayImage = grayImage(:, :, 2);
end
% Get rid of white frame around the image.
allWhiteRows = all(grayImage == 255, 2);
allWhiteColumns = all(grayImage == 255, 1);
grayImage = grayImage(~allWhiteRows, ~allWhiteColumns);
% Display the image.
subplot(2, 2, 1);
imshow(grayImage);
axis('on', 'image');
impixelinfo;
title('Original Image', 'FontSize', fontSize, 'Interpreter', 'None');
%--------------------------------------------------------------------------------------------------------
% Get vertical profile
verticalProfile = sum(grayImage, 2);
% Display the profile.
subplot(2, 2, 3);
plot(verticalProfile, 'b-');
grid on;
% Erase rows with integrated gray levels less than 500 to make sure the blobs are separated.
grayImage(verticalProfile < 500, :) = 0;
%--------------------------------------------------------------------------------------------------------
% Threshold the image.
binaryImage = grayImage >= 1;
%--------------------------------------------------------------------------------------------------------
% Display the image.
subplot(2, 2, 2);
% imhist(grayImage);
imshow(binaryImage, []);
impixelinfo;
axis('on', 'image');
title('Initial Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Maximize window.
g = gcf;
g.WindowState = 'maximized';
g.Name = 'Demo by Image Analyst';
g.NumberTitle = 'off';
drawnow;
%--------------------------------------------------------------------------------------------------------
% Call a closing to fill in and connect some small blobs.
se = true(3, 15);
binaryImage = imclose(binaryImage, se);
% Take the largest 3 blobs.
binaryImage = bwareafilt(binaryImage, 3);
% Fill holes.
binaryImage = imfill(binaryImage, 'holes');
% Display the image.
subplot(2, 2, 3);
imshow(binaryImage, []);
impixelinfo;
axis('on', 'image');
title('Final Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
%--------------------------------------------------------------------------------------------------------
% Get area weighted by shape of outline.
area1 = bwarea(binaryImage)
% Get areas as a simple pixel count.
props = regionprops(binaryImage, 'Area');
area2 = [props.Area]
% Display the original image.
subplot(2, 2, 4);
imshow(grayImage);
axis('on', 'image');
hold on;
% Get the boundary of the mask.
boundaries = bwboundaries(binaryImage);
% Display the outline over the original image.
visboundaries(boundaries, 'Color','r', 'LineWidth',1);
caption = sprintf('Total Area of all %d blobs = %.1f pixels', numel(props), area1)
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');

Categories

Find more on Image Processing and Computer Vision in Help Center and File Exchange

Asked:

M
M
on 11 Dec 2023

Answered:

on 14 Dec 2023

Community Treasure Hunt

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

Start Hunting!