how to read in a curved region of interest that is one plane?

3 vues (au cours des 30 derniers jours)
nines
nines le 20 Mar 2025
Modifié(e) : Matt J le 20 Mar 2025
Hello,
I have a manually drawn a mask on an image that is curved where the red line is the mask, and the black is the the image with the signal; here are two examples:
In the middle of the image there will always be an area where when the mask is applied it will be zero. Additionally, there will always be zeros on boths of the outside of the mask.
here is and example of when it didn't work properly (you can see that there are a bunch of zeros in the middle):
I have been able to read and plot the corresponding values for a straight line (here is an example):
and here is an example of the plot:
and here is the function where I read in the ADC values:
ADC_size = size(ADC);
ROI_resampled = imresize3(ROI, ADC_size, 'nearest') > 0;
% Extract ADC and B0 values within the ROI
adcValues = ADC(ROI_resampled);
and here is the whole code for the plot:
ADC_size = size(ADC);
ROI_resampled = imresize3(ROI, ADC_size, 'nearest') > 0;
% Extract ADC and B0 values within the ROI
adcValues = ADC(ROI_resampled);
% Find the longest sequence of zeros
diffs = diff(zeroIndices);
splitPoints = find(diffs > 1); % Gaps indicate separate zero groups
if ~isempty(splitPoints)
startIdx = zeroIndices(splitPoints(1) + 1); % Start of middle zero block
endIdx = zeroIndices(splitPoints(end)); % End of middle zero block
else
startIdx = zeroIndices(1);
endIdx = zeroIndices(end);
end
% Find the indices just outside the middle zero block
indexAbove = startIdx - 1;
indexBelow = endIdx + 1;
% Ensure indices are within bounds
if indexAbove < 1
indexAbove = NaN;
end
if indexBelow > length(adcValues)
indexBelow = NaN;
end
fprintf('Index above middle zeros: %d\n', indexAbove);
fprintf('Index below middle zeros: %d\n', indexBelow);
%%
% Use indexBelow as reference if available, otherwise indexAbove
if ~isnan(indexBelow)
referenceIndex = indexBelow;
elseif ~isnan(indexAbove)
referenceIndex = indexAbove;
else
error('No valid reference index found.');
end
%%
% Automatically assign distances in mm
x_mm = zeros(size(adcValues)); % Initialize
% Assign values above the middle zero block
for i = indexAbove:-1:1
x_mm(i) = x_mm(i+1) - voxel_size;
end
% Assign values below the middle zero block
for i = indexBelow:length(adcValues)
x_mm(i) = x_mm(i-1) + voxel_size;
end
% Flip the x-axis values
x_mm_flipped = -x_mm;
figure();
plot(x_mm_flipped, adcValues);
Can you help me read line by line the masked values that are next to eachother?

Réponses (1)

Matt J
Matt J le 20 Mar 2025
Modifié(e) : Matt J le 20 Mar 2025
I don't quite understand what you are trying to do, but I have the vague impression you are trying to interpolate an image on a cross-sectional surface (marked by the red line). If so, you should look at the slice command, with particular attention to this example,
and possibly also interp2, interp3, and, griddedInterpolant.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by