How to trace cluster of minimum points from a set of images and plot it in a graph?

1 view (last 30 days)
I want to trace a cluster of minimum points from a set of images and plot it in a graph. You can acces the Image data. Im
expecing a graph as where the points signify the avarge minimum intensity value as a function of pixel number (if we consider (0,0) of cartesian coordinate is same as (0,0) pixel of the image). Or any other ideas on how to do it will be very much appriciated.

Answers (1)

Hassaan
Hassaan on 21 Dec 2023
  1. Read the Set of Images: Load each image in the set into the workspace.
  2. Identify Minimum Points: For each image, find the minimum intensity value and its corresponding pixel location.
  3. Store Minimum Points: Keep track of these minimum points, ideally in an array or list.
  4. Calculate Average Minimum Points: Once all minimum points are collected, calculate the average location.
  5. Plot the Points: Plot these average minimum points on a graph, using the pixel coordinates as the x and y axes.
% Assuming we have N images named img1, img2, ..., imgN
% Initialize arrays to store the minimum points
min_points_x = [];
min_points_y = [];
% Loop through each image to find and store the minimum points
for i = 1:N
% Load the image
img = imread(sprintf('image%d.png', i)); % Replace with actual image names
% Convert to grayscale if it's a color image
if size(img, 3) == 3
img = rgb2gray(img);
end
% Find the minimum point
[min_val, linear_idx] = min(img(:));
[row, col] = ind2sub(size(img), linear_idx);
% Store the points (assuming the top-left corner is (0,0))
min_points_x = [min_points_x; col-1];
min_points_y = [min_points_y; row-1];
end
% Calculate the average minimum points
avg_min_point_x = mean(min_points_x);
avg_min_point_y = mean(min_points_y);
% Plot the average minimum points
plot(avg_min_point_x, avg_min_point_y, 'ro');
xlabel('X (pixel)');
ylabel('Y (pixel)');
title('Average Minimum Intensity Points');
In this script:
  • N is the number of images.
  • sprintf('image%d.png', i) should be replaced with the actual pattern of image filenames.
  • The loop reads each image, finds the minimum value and its position, and stores it.
  • After the loop, the average of the minimum point locations is calculated.
  • The average point is plotted in red on a graph.
Please note that the imread function assumes that the images are in the current working directory and are named in a sequential pattern like 'image1.png', 'image2.png', etc. You'll need to adjust the file reading part to match your actual image file names and paths.
If the images are not named sequentially or are in different formats, you'll need to adapt the code accordingly.
If you liked the anwer and it solved your problem. Please do leave a upvote and a comment means a lot. Thank you.

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!