How do you convert shift and change the size of a group of ones in a zeros 4D matrix?

1 view (last 30 days)
I have a 4D segmented array of size: 4 512 512 200, where 4 is the amount of segmentations. It is an array of ones and zeros. How can i shift the ones in the first segmentation by a certain amount in the right, left, up, or down postition depending on an input by the user. So, basically shifting that group of ones in each 512 by 512 in the first segmmentation by the same amount and in the same direction in all 200 images.
Also how can the same thing be done, but insead enlarging or decreasing the size of those ones by an amount inputted by the user?

Answers (1)

Sai Bhargav Avula
Sai Bhargav Avula on 17 Feb 2020
Edited: Sai Bhargav Avula on 17 Feb 2020
Hi,
You can achieve this by
Extracting the first channel of each image assuming image_4d is your 4D matrix
Im_trans = image_4D(1,:,:,i)
Im_trans contains the first channel of your ‘i' th image.
Now use imtranslate to translate
Image_translated = imtranslate(Im_trans,[x,y],'FillValues',0);
by filling the left over parts with 0's the final image would only result in shifing the 1's of the original image.
Where x,y are the inputs from the user. This can be fed by using input command.
By using a for loop over the same can be repeated for all the 200 images.
Functions like imdilate and imerode can be used to enlarge and decrease the size and the input for these functions can be given by user by using the input command
Hope this helps !

Community Treasure Hunt

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

Start Hunting!