From ImageJ to Matlab Conversion
Show older comments
HI.
Can someone translate this ImageJ piece of code to MATLAB equivalent. If not, is there an app for automated conversion between those two formats?
Thank you
for(i=1;i<=nSlices;i++){
setSlice(i);
run("Translate...", "x="+i*xTranslate+" y="+i*yTranslate+"
interpolation=None slice");
}
6 Comments
Considering that the subset of persons that know how to script ImageJ and know matlab is probably not that big, if you know what the above code is doing (particularly the setSlice) you'll get more chance of getting help.
All I can guess is that it translate (which you can do with imtranslate) some slices. It's unknown what these slices are.
Stelios Fanourakis
on 12 Jul 2018
Guillaume
on 12 Jul 2018
Translating a stack of image is trivially done in matlab with imtranslate. So, if it's all you need to do, just use that function.
Stelios Fanourakis
on 12 Jul 2018
Guillaume
on 12 Jul 2018
Oh, I didn't realised it was you. Well, as you've requested, I will not get involved in your questions.
Guillaume
on 12 Jul 2018
For others, this is a follow-up to
- griddedinterpolant-and-gridvectors-turn-image-to-binary
- does-anyone-know-why-the-images-appear-that-way
- can-imtranslate-and-squeeze-be-combined-to-one-code-line
and many more.
Answers (1)
Sean de Wolski
on 12 Jul 2018
Edited: Sean de Wolski
on 12 Jul 2018
Looks like imtranslate should work. My interpretation of that is: loop over slices, translate each slice by some amount (that value may vary by slice - I don't know). You may not be able to do it all in one shot but it should certainly work. Something along these lines, not tested.
VT = zeros(size(V),'like',V)
for ii = 1:size(V,3)
VT(:,:,ii) = imtranslate(V(:,:,ii), [something_row(ii), something_col(ii)])
end
Can you describe what you're trying to do, i.e. what is the end goal?
15 Comments
Stelios Fanourakis
on 12 Jul 2018
Stelios Fanourakis
on 12 Jul 2018
Sean de Wolski
on 12 Jul 2018
[row(ii), col(ii),0,0]
is four elements. It should be two to translate in row/col or three to translate in row/col/slice. It won't translate into 4d.
Stelios Fanourakis
on 12 Jul 2018
Stelios Fanourakis
on 12 Jul 2018
Sean de Wolski
on 12 Jul 2018
Squeeze a 4d grayscale image to make it 3d.
Apparently to translate into 3d, you need a 3d matrix. That might mean it makes more sense to do the 3d part of the translation all at once. I.e. loop over translating in 2d if slices translate different amounts, then do the 3d piece all at once.
I don't really understand what your goal is but certainly some combination of these steps is what you want.
Stelios Fanourakis
on 12 Jul 2018
Rik
on 12 Jul 2018
Nobody is born knowing how to do stuff in Matlab. A great method of learning how Matlab works is to actually read the documentation of function you're guessing might be useful. The documentation is quite good, it's one of the big advantages over Octave.
Permute changes the order of dimensions of an array. You could certainly use it here, but you don't necessarily need it.
Stelios Fanourakis
on 13 Jul 2018
Edited: Stelios Fanourakis
on 13 Jul 2018
Stelios Fanourakis
on 13 Jul 2018
Stelios Fanourakis
on 13 Jul 2018
Sean de Wolski
on 13 Jul 2018
Different y/x but no translation in z? If so, squeeze the stack of images to get 3d, run the loop over each one like I did above, and pass just the x/y parameters into imtranslate. Basically exactly what I have in the answer.
Sean de Wolski
on 13 Jul 2018
permute is the equivalent of imagej reslice I believe. I haven't looked at ImageJ since 2009 when I rewrote everything we were doing there in MATLAB. There are no plugins to my knowledge and with my knowledge of ImageJ at the time getting as far away from it as possible was the best practice.
Stelios Fanourakis
on 13 Jul 2018
Stelios Fanourakis
on 15 Jul 2018
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!