Save extreme points in a single position
    조회 수: 4 (최근 30일)
  
       이전 댓글 표시
    
%Greetings, I need to verify if there is a way to keep the first position of the points of the Extrema function in my element. The point is that %during the sequence of images the points move and I need them to remain fixed in one position on the bottle. Otherwise find out if there is a %way to keep track of the bottom of the bottle and the top cap. Greetings and I enclose the code that I have at the moment
clc 
close all
clear all
Dir = dir('*.tif');
tt=1; 
Im = imread(Dir(tt).name);
seq = double(zeros(591,601,length(Dir)));
Minarea = 1500;
Mtaco=[];
for tt=190:369
    Im = imread(Dir(tt).name);
    Im2 = imrotate(Im,-90);
    Im3 = 3*Im2(180:770,60:660,:);
    Im3 = Im3(:,:,1) < 5959;
    se = strel('disk',5);
    cerrada = imclose(Im3,se);
    bw = bwareaopen(cerrada,15000);
    filled = imfill(bw, 'holes');
    seq(:,:,tt) = filled;
    imagesc(filled), axis image, axis off, colormap gray,
    pause(0.001)
    stats = regionprops(seq(:,:,tt),'Area','Centroid','Extrema','Orientation');
    hold on
    kk = [stats.Area] > Minarea;
    stats = stats(kk);
    Extrema3 = stats(1).Extrema;
    plot(Extrema3(1,1),Extrema3(1,2),'*c'),pause(0.01)
    plot(Extrema3(2,1),Extrema3(2,2),'*r'),pause(0.01)
    plot(Extrema3(3,1),Extrema3(3,2),'og'),pause(0.01)
    plot(Extrema3(4,1),Extrema3(4,2),'oy'),pause(0.01)
    plot(Extrema3(5,1),Extrema3(5,2),'or'),pause(0.01)
    plot(Extrema3(6,1),Extrema3(6,2),'oc'),pause(0.01)
    plot(Extrema3(7,1),Extrema3(7,2),'ob'),pause(0.01)
    plot(Extrema3(8,1),Extrema3(8,2),'om'),pause(0.01)
    Mtaco = [Mtaco; Extrema3];
    hold off
end 
%Here I attach images of the problem that happens when the extreme points move through the image



댓글 수: 0
답변 (1개)
  Nipun
      
 2024년 5월 30일
        Hi Patricio,
I understand that you want to save extreme points (minimum and maximum) of a matrix in a single position. Here’s how you can do it concisely:
% Sample matrix
A = randi(100, 10, 10);
% Find minimum and maximum values and their indices
[minVal, minIdx] = min(A(:));
[maxVal, maxIdx] = max(A(:));
% Save extreme points in a single vector
extremePoints = [minVal, minIdx; maxVal, maxIdx];
disp(extremePoints);
This saves the minimum and maximum values along with their linear indices in the matrix extremePoints.
Hope this helps.
Regards,
Nipun
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

