Lot
Lot

Reputation: 1

Select certain slices in 3D image

I have a 3D image and I want to select certain slices within that image. So let's say it's a 3D image with dimensions 100x100x40. What I want is to select the image intensities within a certain range for every dimension; x=[22,39], y=[17,32], z=[26,42]. I'm thinking a for loop that runs through all indices within the image and keeps those intensities that are within the range for every dimension. Any clue on how I should do this?

Btw, I can't use imcrop cause I want my output image to have the same dimensions as the input.

Edit

I figured I could do something like this:

NewIndex_x = 1;
index_x = [];
for i=22:39;
    index_slice_x = find(Im(i,:,:));
    index_x(NewIndex_x) = index_slice_x;
    NewIndex_x = NewIndex_x + 1;
end

find does not work for a range so I thought I could do this for all x,y and z slices and then find the overlapping indices. My for loop does not work, any ideas on how to properly append an array to another array within a for loop?

Cheers!

Upvotes: 0

Views: 86

Answers (1)

mkfin
mkfin

Reputation: 517

Was not exactly sure if you wanted a subimage based on the x,y,z range and then apply the intensity level to that or something else. The code below does this. So it first gets the subimage and then sets the intensity level filter for that. If this is not what were aiming for, please add some clarification. Hope this helps.

% Sample data
im = round(rand(100,100,40)*255);

% Subimage that we want to process
xrange=22:39;
yrange=17:32;
zrange=26:39;

% Get all points from within the defined range
imnew = zeros(size(im));
imnew(xrange,yrange,zrange) = im(xrange,yrange,zrange);

% Now you can apply your intensity level filter if you want
min_intensity_level = 100;
imnew = imnew .* (imnew > min_intensity_level);

% At this point, imnew contains the points within the specified range that
% also exceed the minimum intensity level.

Upvotes: 1

Related Questions