How to use arguments validation functions for multi-frame images?

2 views (last 30 days)
Hi, I am designing a function to analyse an image sequence frame by frame to return a vector of time according to the cardiac cycle. For the image file argument validation, how do I customise a validation function for these two purposes:
1) ensure each sequence have a reasonable duration (number of frames, minimum 75 frames in total) 2) must be a 3D array
Thanks in advance!
function peaktimes = detectCardiacPhase(img, frameRate)
arguments
img (:,:,:) {mustBeNumeric}
frameRate double {mustBePositive} = 15 %default value of frameRate is 15 frames/sec
end
end

Accepted Answer

Ashutosh
Ashutosh on 8 Jun 2023
From what I am understanding, you need your function to perform 2 preliminary checks on any input video (or in other words, image sequence) file:
  1. Video file must have at least 75 frames, ie the sequence must have at least 75 images.
  2. The image sequence must be 3 dimensional. I am assuming you mean each image is 2 dimensional and each image in the sequence is stacked on top of each other to make the sequence 3 dimensional. Hence the third dimension (or depth) of the sequence is equal to the number of frames in sequences
I will admit I am not entirely sure I got these right, so let me know if something is amiss.
You can check the 2 conditions as follows:
function peaktimes = detectCardiacPhase(img, frameRate)
errorMsg1 = "The entered sequence is not 3D";
errorMsg2 = "The entered sequence is too short";
if length(size(img)) ~= 3 % check if input is 3D
error(errorMsg1);
elseif size(img,3) < 75 % check if there are at least 75 frames
error(errorMsg2);
end
% main
% function
end
You can also refer to the documentation for the error function.

More Answers (0)

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!