Can I apply imtranslate to a 4D image?
1 次查看(过去 30 天)
显示 更早的评论
Stelios Fanourakis
2018-7-3
Can you please give me examples of imtranslate code lines that is being applied to a 4D DICOM image?
I get the errors that imtranslate is taking a 3D image as input.
6 个评论
Rik
2018-7-3
If it is a rigid translation (no rotation or shear), you can loop through the fourth dimension to translate the first 3 dimensions, and then follow it up with a second loop to translate the last dimension.
Stelios Fanourakis
2018-7-3
编辑:Stelios Fanourakis
2018-7-3
Can you please give me an example line code?
Thank you
Rik
2019-7-4
In this context of 3D and 4D images, I would like to ask a very baisc doubt of mine . Light field or Plenoptic images are considered to be 4 D images. If I have them in png format, then how do I read and show it in Matlab. Does normal imread and imshow functions do the reading/displaying of 4 D images too?
Rik
2019-7-4
The png format doesn't actually support multidimensional images as far as I'm aware. So if you have png file, you have 2D RGB images.
A more fundamental question is how you would envision a 4D display function to work. There are some 3D tools you could use, and you could add color to encode a forth dimension.
Also, a quick Google search didn't explain why you would consider such an image itself to be 4D.
parvathy prathap
2019-7-8
Thanks for your answer. Plenoptic OR light field images are theoretically considered to be 4 D images. I have seen a couple of datasets of light field images where the images are in png format or tiff format. That is why i was wondering if light field images could be available in these formats too. Please let me know if you know anyone working in the field of light field/plenoptic image processing. I am new to this field.
Rik
2019-7-8
They may be 4D theoretically, but if they're saved as png, they are RGB 2D. Tiff has a some more options, although as I understand it is also limited to 3D. Just like a map of the world, that could be a lower dimensional representation of the higher dimensional actual object.
The fundamental question of how you would display a 4D object is also still unanswered.
And no, I don't know anyone working in such a field.
采纳的回答
Rik
2018-7-3
编辑:Rik
2018-7-3
The code below implements what I mentioned in my comment. It might also be the case that your 4D is actually a 3D in the same format as in the mri.mat example bundled with the IPT. In that case, you could simply have used squeeze.
S=load('mri');%load a builtin 3D example
IM=repmat(squeeze(S.D),1,1,1,10);%generate a 4D
translation_vector=[13 40 -1 2];
IM2=imtranslate(IM(:,:,:,1),translation_vector(1:3));
for n=2:size(IM,4)
IM2(:,:,:,n)=imtranslate(IM(:,:,:,n),translation_vector(1:3));
end
if translation_vector(4)~=0
IM2b=imtranslate(squeeze(IM2(1,:,:,:)),[0 0 translation_vector(4)]);
IM2b=permute(IM2b,[4 1 2 3]);
for n=2:size(IM2,1)
IM2b(n,:,:,:)=imtranslate(squeeze(IM2(n,:,:,:)),[0 0 translation_vector(4)]);
end
IM2=IM2b;
end
12 个评论
Stelios Fanourakis
2018-7-3
@Rik Is translation_vector=[13 40 -1 2]; the translation parameter where implements in order to alter the image position?
I want those parameters to be loaded by a txt file. Don't worry I have done it. I'd only like to tell me how to combine squeeze and imtranslate commands. Like this for example?
data = dlmread('imgpositions.txt');
[row, col] = size(data);
x=data(1:row, 1);
y=data(1:row, 2);
H = squeeze(imtranslate(im2(:,:,:,:),[col,row,0],'OutputView','full'));
Translated = H(:,:,:,sliceIndex);
I get the below error
Error using imtranslate>postValidateTranslation (line 506)
When TRANSLATION is a three-element vector, the input image, A, must be 3-D.
Error in imtranslate>preparseSpatialReferencingObjects (line 527)
postValidateTranslation(varargin{1},translation);
Error in imtranslate (line 129)
[R_A, varargin] = preparseSpatialReferencingObjects(varargin{:});
Error in experiment (line 51)
H = squeeze(imtranslate(im2(:,:,:,:),[col,row,0],'OutputView','full'));
Rik
2018-7-3
Have you read what squeeze does? Why do you want to combine squeeze and imtranslate?
My code shows you how you can use imtranslate on a 4D image. To have a 4D translation, you need a 4-element vector.
Stelios Fanourakis
2018-7-3
A few questions:
My image is already a 4D image, therefore I can exclude the repmat line, right? Where translation_vector is my [col, row, 0] from the txt file, right?
Everything else remains as it is and my final image is the IM2b(n,:,:,:) right?
Rik
2018-7-3
I forgot to add one line, so I added it now. With the new code, the final translated image is in the IM2 variable.
You can skip the first two lines, as you already have a 4D image.
If you want to apply a translation, you need to specify for each dimension how much it should be moved into which direction. Therefore, if you have a 4D image, you'll need 4 elements in your translation vector. I can't tell you how you get your information from your text file, because you didn't share enough information to do so.
Stelios Fanourakis
2018-7-3
My txt files contains 15 rows and only 2 columns. So it is useful only [col,row,0] as my translation vector. If I make it [col,row,0,0] you think it will work?
Stelios Fanourakis
2018-7-4
Can you please tell me how to load the translation parameters from a txt file? How many columns the txt should have? 4? It currently has only 2 (x,y). Should it had more?
Rik
2018-7-4
Your vector should have 4 elements. If you do not want to translate the 3rd and 4th dimension, just set those vector elements to 0. I don't know what kind of data you have in your text file and what they describe, so I can't possibly comment on how you should create your vector based on the file.
Stelios Fanourakis
2018-7-4
That's what I did previously but it didn't work as expected. In my txt file I have two columns and 15 rows (same number as images). For every image, corresponds a row with x (horizontal, 1st column) and y (vertical, 2nd column). Images are supposed to be translated based upon those values. For instance if
0 3 Then the corresponding image should be 0 to its x horizontal position and 3 mm lifted up to its y vertical axis. All images have the same x value, which means they are aligned properly horizontal , but the have slight differences on their y vertical axis, so one may be upper or lower than others. Am I clear? How can I do that?
If I use like [row,col,0,0] then the whole stack of images is translated to a degree but I want individually slices to have different displacements
Rik
2018-7-4
That is completely different from your original question. If they are actually 15 sets of 3D images that are stored in a 4D array, you should use a for-loop and use the normal imtranslate for each 3D element.
Stelios Fanourakis
2018-7-4
I cannot write imtranslate line 15 times. What about if I had 100 or 200 or even more images and what about if it happened to be changed. Any other way to do it? The positions will be fixed and if images are changed the new ones will be displaced the same.
更多回答(1 个)
Matt J
2018-7-4
编辑:Matt J
2018-7-4
Another possibility below. This should work on arrays of any dimension.
F=griddedInterpolant(your4Darray);
g=F.GridVectors;
for i=1:numel(g)
g{i}=g{i}-translation_vector(i);
end
result=F(g);
20 个评论
Rik
2018-7-4
That's a good option for the question as it was posted, but apparently not what OP intented
Stelios Fanourakis
2018-7-4
Thanks Mat. It's nice but not what I asked. I'd like to translate separate each image in a stack of images.
Stelios Fanourakis
2018-7-4
@Mat. Why the - sign in the g{i}=g{i}-translation_vector(i); line?
What about if it was + or *. Will it change somehow?
Stelios Fanourakis
2018-7-4
Different images needs to be shifted either up or down by y. How do I do that?
Stelios Fanourakis
2018-7-5
I think your code is correct and brilliant. But I need to fix the images so I can test. Do you know why the images in the plots appear like that (see attached pic)? Where before I add your code was normal grayscale DICOM images. Does your code affect it somehow? I don't think so but I wonder why I got that result
Matt J
2018-7-5
I don't know how to interpret what the pic shows, but bear in mind that if your original image was an integer type, it won't be after the interpolation.
Stelios Fanourakis
2018-7-5
The F=griddedInterpolant(your4Darray); line asked me that (your4Darray) should be double and I did it double. You think it might be the reason why my images appear that way? They are normal DICOM images.
Stelios Fanourakis
2018-7-5
I don't do that. How do I find out what type are my original images? They are 4D uint8.
Stelios Fanourakis
2018-7-5
I used the uint8(result) command to turn it back to normal but I cannot see to be translated now. See attached pic. I once got it as I'd like to be and the next time I lost it.
Stelios Fanourakis
2018-7-6
@Mat. Please see my latest attached pic (exmp3.jpg). Although the displacement of the images seem to be correct. I am not able to see the images now. Like they have disappeared or stretched too far away. Have any idea for why this can happen?
Thank you
Matt J
2018-7-6
Not really. But it seems to be an issue in whatever you are doing to display the result, not in the computation of the translation. Try normalizing the maximum in your data to 1 or 255.
Stelios Fanourakis
2018-7-6
Even that line I use
a = uint8(255 * mat2gray(result));
And I now get totally black images
Stelios Fanourakis
2018-7-6
Do griddedInterpolant or GridVectors functions affect the display of the images somehow? I don't know because it is the first time I use them
Stelios Fanourakis
2018-7-15
I have another assumption. im2 is a 4D interpolated stack of images (stack out of 15 images) using interp3.
Interpolation to me, means that it creates in between images. For example, if there is 1 to 2 image, the interpolation will give us 1.5 image. Am I correct? So that's what interp3 does. It increases the number of images above 15, where they really are.
Then, by importing im2 to GriddedInterpolant, again another interpolation takes place, so even more subimages are created. Thus, the total number of slices that consist the stack may exceed 30, but, definitely it won't be 15 where it started.
Then, with GridVectors I turn it to cell array and by multiplying with the translation_vector, supposedly they are shifted. BUT, the translation_vector matrix is consisted out of 15 rows and 2 columns. 15 rows as the original images NOT the interpolated ones. So, a lot of images do not shift.
Am I right to my assumption. Is this more clear so we can find a solution?
Stelios Fanourakis
2018-7-15
@Matt. I though of another solution. When I use result = F(g) I apply interpolation again to g which are the original set points (image) multiplied by translation_vector.
That means that the original image has already been shifted plus a new interpolation coming on the way (F(g)). Does it make it somehow to be smushed or squeezed?
If I visualize with only g without F(g) I get errors later on to the uicontrol of the slider (e.g. Index Exceeds Matrix Dimensions).
Would it be correct to visualize only with g?
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)