이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
GriddedInterpolant and GridVectors turn image to binary?
조회 수: 2 (최근 30일)
이전 댓글 표시
Can someone please tell me if GriddedInterpolant and or GridVectors turn an image to binary format. Why is this happening and how can it be reversed?
I use that code line
t = double(im2)
F=griddedInterpolant(t);
g=F.GridVectors;
Where im2 is my original image
댓글 수: 18
Stephen23
2018년 7월 8일
Duplicate:
https://www.mathworks.com/matlabcentral/answers/409120-does-anyone-know-why-the-images-appear-that-way
Guillaume
2018년 7월 8일
You have received plenty of helpful answers. Please continue the discussion in your other question. We would only end up replicating the same discussion here, wasting everyone's time.
The way I see it, you don't understand image display or something similar. The only way we can explain clearly what is going on is if you supply all the inputs (image, etc.) and the exact code you're using from start to end.
In addition, this particular question is a bit pointless since in your code nothing change im2 and neither outputs of griddedInterpolant or GridVector can be interpreted as images.
Stelios Fanourakis
2018년 7월 8일
편집: Stelios Fanourakis
2018년 7월 8일
What do you mean? I provided my image code at my last comment in the previous thread. After this the images are displayed using imshow(squeeze(im2(:,:,i,:))) Nothing more to declare.
YOu do have all appropriate material to provide a valid solution. May I keep that question open? Someone may knows how to tune griddedInterpolant or GridVectors and make it no appear binary image.
Guillaume
2018년 7월 8일
Note: I hesitated to close the question as unclear. In the code, you've provided, we start with an image im2 then three lines of code that do not affect or touch im2. So, whatever your im2 was before the code, it's still the same after and your question makes no sense.
Stelios Fanourakis
2018년 7월 8일
It makes sense. im2 is a normal DICOM grayscale image that shows soft tissue. This is the whole version of the code I use:
t = double(im2)
F=griddedInterpolant(t);
g=F.GridVectors;
for i=1:numel(g)
g{i}=g{i}*translation_vector(i);
end
result=F(g);
So the resulting image is "result". It appears as binary black and white image with no information at all. After the F=griddedInterpolant(t) line it becomes binary with shape and the last line of code result=F(g) is shapeless black and white.
Guillaume
2018년 7월 8일
편집: Guillaume
2018년 7월 8일
Sigh! And as predicted we're back to the same fruitless discussions as in the other question.
After the F=griddedInterpolant(t) line it becomes binary with shape
What is "it"? It can't be F since F is a function, not an image. Yet that line produces nothing else but F and doesn't change anything.
And then we've got the statement binary with shape No idea what that mean, nor how you establish that the image is binary. Most likely whatever "it" is, it's not binary but appears that way because of the way you're displaying it.
Same for the last line of code, it's probably not binary.
In any case, until we get a mat file containing im2 (and translation_vector) we can't reproduce your problem.
Stelios Fanourakis
2018년 7월 8일
Use makeImIsoRGB.m to get the im2 image. It takes a stack of images as input and outputs a 4D interpolated one. And the translation vectors are columns and rows of the txt file. Please, reproduce it and tell me what is wrong. Thank you
Stelios Fanourakis
2018년 7월 8일
The change in the image comes when I convert it to double. After the double() line it becomes white with shapes
Guillaume
2018년 7월 8일
Make our life easier, and again, provide a mat file containing im2 (and translation_vector).
The change in the image comes when I convert it to double
As you've been told in the other question. double doesn't change the values in the image. Whatever it was before the call to double it's still the same after, and the problem is with the way you display it.
Matt J
2018년 7월 8일
and the problem is with the way you display it.
@Stelios, Further evidence that your data isn't actually binary is in the histogram that you provided us here. If the data had become binary, the histogram would only be non-zero at 2 values (zero and one). As you can see there, however, the data takes on many more than 2 values.
Stelios Fanourakis
2018년 7월 8일
YOu also need to have DicomReader.m to create the stack of images. Let me know if you need all the 15 images
Stelios Fanourakis
2018년 7월 8일
편집: Stelios Fanourakis
2018년 7월 8일
@Matt. If not imshow, then what? Never had problem with imshow. I only face a problem with the image translation from the txt file
Jan
2018년 7월 12일
@Stelios: The code is almost useless, because it is not documented and does not have a help text. Understanding the code requires to guess the intention. I'd never do any serious work with such a code.
The code should be simplified, e.g.:
if strcmpi(class(sampleSlice),'uint8')
Img = uint8(Img);
elseif strcmpi(class(sampleSlice),'uint16')
Img = uint16(Img);
elseif strcmpi(class(sampleSlice),'uint32')
Img = uint32(Img);
elseif strcmpi(class(sampleSlice),'uint64')
Img = uint64(Img);
elseif strcmpi(class(sampleSlice),'int8')
Img = int8(Img);
elseif strcmpi(class(sampleSlice),'int16')
Img = int16(Img);
elseif strcmpi(class(sampleSlice),'int32')
Img = int32(Img);
elseif strcmpi(class(sampleSlice),'int64')
Img = int64(Img);
elseif islogical(sampleSlice)
Img = logical(Img);
end
is much smarter when written as:
Img = cast(Img, class(SampleSlice));
Or even better: Do not create a false() array initially and waste time with a conversion, but start with:
if strcmpi(dicom_header.PhotometricInterpretation, 'RGB')
ImgSize = [dicom_header.Height, dicom_header.Width, length(file_names), 3];
else
ImgSize = [dicom_header.Height, dicom_header.Width, length(file_names)];
end
Img = zeros(ImgSize, class(SampleSlice));
Stelios Fanourakis
2018년 7월 12일
Accepted. But the simplification is not an integral part right now. I am trying to fix the display of images. Once have done, I 'll see how to improve the overall code. At that time, DicomReader.m and makeImIsoRGB.m work fine
Jan
2018년 7월 12일
@Stelios: Anywhere in your workflow is a problem. You cannot find out, where it is, so you have posted the code, such that the readers can find the point. But the posted code does not allow an identification, if it is confusing and weakly written.
The original question was:
tell me if GriddedInterpolant and or GridVectors turn an image to
binary format
It did not get clear, what this means or why you have this impression. I still assume the best answer is "no, they do not convert the image to binary format".
I give up here.
Stelios Fanourakis
2018년 7월 12일
편집: Stelios Fanourakis
2018년 7월 12일
@Jan. I really do appreciate the time and effort you put in order to help me, but, if you feel that in any way I cause you frustration, again, I remind you that is not obligatory by your side to respond to my questions. If you can understand the problem and have a valid solution, then, you are more than welcome to provide it. Other may also benefit.
My code is fine. It may needs a bit of cleaning and simplification but it is a very strong code that works and gives the outcome I'd like. It is only that specific part of code I don't understand and needs to be modified. The code is more than fine.
답변 (3개)
Matt J
2018년 7월 8일
편집: Matt J
2018년 7월 8일
The answer is no, griddedInterpolant cannot change the data type of the input. As you can see in the examples below, if the input to griddedInterpolant are single floats, then the output will be single as well. Likewise, if the input is double, the output will be double. You can do a similar check on any other input data you are interested in.
>> in=rand(3,'single'); F=griddedInterpolant(in); out=F(2.5,2.5); whos in out
Name Size Bytes Class Attributes
in 3x3 36 single
out 1x1 4 single
>> in=rand(3); F=griddedInterpolant(in); out=F(2.5,2.5); whos in out
Name Size Bytes Class Attributes
in 3x3 72 double
out 1x1 8 double
Similarly, GridVectors cannot be responsible for a change in input-to-output type/precision. GridVectors is not even a function. It is a property of the griddedInterpolant class.
댓글 수: 2
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?
Stelios Fanourakis
2018년 7월 9일
Nobody can help me on this?
댓글 수: 9
Matt J
2018년 7월 9일
Your question was answered and you accept-clicked the answer. As far as the posted question is concerned, there is nothing left to add.
Stelios Fanourakis
2018년 7월 9일
I accepted your answer not because my problem solved but because I agree to whatever you say to your answer. The problem of the binary images still remain and I don't know how to fix it. Please help
Matt J
2018년 7월 9일
Well, that would need to continue in one of the earlier threads you posted on the subject. It is off-topic for the question you posted here.
Stelios Fanourakis
2018년 7월 9일
Whatever. it is the least that I am concerned. I need a solution as fast as possible
Guillaume
2018년 7월 9일
Whatever. it is the least that I am concerned. I need a solution as fast as possible
Seriously? And you expect help after that?
You have been given the answer several times in the other question (and here). You do not understand what you are displaying and are interpreting the result of imshow incorrectly. So, let me repeat it one last time: your image is not binary.
You have also been asked several times to supply the image, not a bunch of files that could potentially, maybe, generate the image. Just the image itself as a mat file. The harder you make it to answer your question, the less likely you'll get help.
Dismissive attitude to our comments also doesn't help.
Stelios Fanourakis
2018년 7월 9일
Seriously? And you expect help after that?
Excuse me. It is not offending. I just expressed that I don't care which thread my topic is, as long as it gets resolved. If I feel that one thread is stuck and do not move forwards I'll have to open a new thread with a slight different question but same outcome.
I give you all 15 DICOM Images. If possible, help me. By helping someone in need, all glory and respect is yours.
Stelios Fanourakis
2018년 7월 9일
Just use Img=DicomReader('1st image name') and then im2 = makeImIsoRGB(Img,[1,1,15],2.0,'cubic') to get the im2 and then apply the rest of the code.
Jan
2018년 7월 12일
I don't care which thread my topic is, as long as it gets resolved.
While you do not care, the readers do. Posting multiple threads is confusing an the readers loose the overview. This is not an efficient method to use the work of voluntary helpers.
Stelios Fanourakis
2018년 7월 9일
I gave all my resources and explanations. Anyone help? It is urgent. I don’t think it is so difficult. Come on
댓글 수: 35
Stelios Fanourakis
2018년 7월 9일
편집: Stelios Fanourakis
2018년 7월 9일
Mat did you try it yourself and worked? I tried it but nothing happened. See results attached image. If you got results yourself please attach
Stelios Fanourakis
2018년 7월 10일
I have an idea. I suppose that it messes with the translation_vector(i) and although the translation of the images is correct, since, the values of the translation_vector are negatives it is capped to either a threshold of 0 or 1, since it is double.
So, how else can I apply the translation_vector?
Guillaume
2018년 7월 10일
편집: Guillaume
2018년 7월 10일
I don’t think it is so difficult. Come on
Well, then why can't you fix it? My feeling is that the problem is you're not listening.
Again, griddedInterpolant and gridVector will not binarise, or cap anything. These functions don't care what the inputs are. They will just interpolate whatever is passed in.
In any case, I've asked multiple times for a mat file containing im2 and |translation_vector. I don't want a bunch of files and scripts that I have to run just to see your problem. Until you do, it's the last you'll hear from me.
Stelios Fanourakis
2018년 7월 10일
@Guillaume
Please, read my last comment, I ask different ways to apply translation_vector since I assume it has to do with the negative values of the txt file, and they are capped to a threshold of 0 or 1 since it is double(). There must be different ways, to apply translation matrix. I believe this is the problem.
For one last time, I send you all necessary files to run the app. You will need all of them in the same folder to run. im2 is a product of both DicomReader.m and makeImIsoRGB.m. translation_vector reads col and rows of imgpositions.
You can use whatever images you have (series of images, not just one). They must have the same extension (e..g .dcm,.jpg,.bmp etc). If it comes up with an error for the subplot(2,2,4) just delete it. We don't need it for now.
_ _ _I've asked multiple times for a mat file containing im2 and |translation_vector. I don't want a bunch of files and scripts that I have to run just to see your problem. Until you do, it's the last you'll hear from me.___
You cannot have a single mat file for all of those. YOu need all of those. If you just need to see the code use the experiment.m
I have sent it already. Please, take a better look.
Stelios Fanourakis
2018년 7월 10일
Sorry. Not whatever images you have. Just choose only .dcm series. If you don't have and need mine. Get those I send you.
Guillaume
2018년 7월 10일
For the very last time, I don't want a bunch of files. I want just one mat file that contains im2 and translation_vector. How hard is it to understand? You clearly have these already in your workspace, select both, right-click, save As... and attach the mat file.
Stelios Fanourakis
2018년 7월 10일
Read all my comments from your last comment until now. You'll understand. im2 is a product of makeImIsoRGB.m function. You need it to have so you can call it. Same rule applies for the rest. I cannot make it easier for you. Sorry!
Matt J
2018년 7월 10일
편집: Matt J
2018년 7월 10일
So, how else can I apply the translation_vector?
I'm really quite puzzled that you are not using imtranslate() in a loop as suggested by Rik, an answer which you accepted. Seems like a simple enough approach.
Stelios Fanourakis
2018년 7월 10일
I explained Matt that Rik's suggestion didn't apply the translation separately to every image of the stack. The whole stack was translated to a degree but that's not what I want. Your suggestion seems nice, but I don't know why images appear that way.
Matt J
2018년 7월 10일
편집: Matt J
2018년 7월 10일
Rik's suggestion seems very applicable to me. You have a 3D volume im2(:,:,:, i) for each i=1,...,15. Is that not correct? Then you can simply do,
im3=nan(size(im2)); %pre-allocate
for i=1:15
im3(:,:,:,i)=imtranslate(im2(:,:,:,i), [Tx(i),Ty(i),Tz(i)]);
end
where [Tx(i),Ty(i),Tz(i)] is the translation vector for the i-th 3D image. Is that not what you are trying to do?
Stelios Fanourakis
2018년 7월 10일
@Mat. I infer that your logic is right but for some reason I cannot know. I get the error "Index exceeds matrix dimensions." for the line
im3(:,:,:,i)=imtranslate(im2(:,:,:,i), [Tx(i),Ty(i),Tz(i)]);
with no further explanation. I am trying to resolve it
Stelios Fanourakis
2018년 7월 11일
Again Matt. Same outcome as previously. There is a standard translation which is fixed. The image positions on the y axis are differed. So I should see different displacements on the images. Instead, I see the same displacement to the whole stack.
Stelios Fanourakis
2018년 7월 11일
편집: Stelios Fanourakis
2018년 7월 11일
I just need to find a way to fix the display of those images that are resulted from your suggestion
Stelios Fanourakis
2018년 7월 11일
Gosh! I wouldn't expect to be that difficult. I know it's just a problem with the image display but nobody seems to find that.
Jan
2018년 7월 12일
@Stelios: While I still assume, that the solution will be easy, the description of the problem is still not clear. It is really hard to help you.
Stelios Fanourakis
2018년 7월 12일
@Jan. I am sorry, don't know how to express it more simple. What is the part of my problem that you don't understand?
Jan
2018년 7월 12일
- What exactly are the inputs? Why not posting "im2" as MAT file?
- You've posted a lot of code, but it is not clear, which is the relevant part.
- Why do you assume the "GriddedInterpolant and or GridVectors turn an image to binary format"? This assumption is not correct.
Stelios Fanourakis
2018년 7월 12일
im2 that is the output of makeImIsoRGB.m is the input for the visualization. I sent you all images. I don't know how to post im2 as a mat file. I don't actually understand that request
This is the relevant part
t = im2double(im2)
F=griddedInterpolant(t);
g= F.GridVectors;
for i=1:numel(g)
g{i}=g{i}*translation_vector(i);
end
result= F(g)
r=uint8(result*255)
After that images are being displayed using imshow
Because after GriddedInterpolant and GridVectors, im2 image becomes black and white without information (binary).
Jan
2018년 7월 12일
편집: Jan
2018년 7월 13일
Insert this line of code, after im2 has been created:
save('im2.mat', 'im2') % Typo! "same" -> "save", of course
The same for translation_vector.
Because you did not provide data for im2 and translation_vector I replaced them by rand value. Afterwards I get some negative values also, but the output r is definitely not any kind of "binary". You did not mention, why you assume that "im2 image becomes black and white".
After all these comments and posted code, it is still not clear, what your problem is and what you want to achieve.
Stelios Fanourakis
2018년 7월 12일
편집: Stelios Fanourakis
2018년 7월 12일
Undefined function or variable 'same'.
Error in experiment (line 43) same('im2.mat', 'im2')
Jan take a look at this comment https://uk.mathworks.com/matlabcentral/answers/409349-griddedinterpolant-and-gridvectors-turn-image-to-binary#comment_587341
I attached New.zip. You have all the images you need there. You just select one image that goes input to DicomReader.m and the output of it (im) goes as input to makeImIsoRGB.m where you get the final im2.
Also, take a look at that comment
https://uk.mathworks.com/matlabcentral/answers/409349-griddedinterpolant-and-gridvectors-turn-image-to-binary#comment_587758
You'll find all functions you need + imgpositions.txt where the translation_vector is loaded. translation_vector is the rows and columns of that txt.
Stelios Fanourakis
2018년 7월 13일
Now definitely, here I attach them. It seems I cannot attach im2.mat cause its 16 MB and the limit here is only 5MB. Jan can you please give me your email address to forward you the im2.mat?
Stelios Fanourakis
2018년 7월 13일
@Jan. I need your email to forward im2.mat cause it's too big to attach
Jan
2018년 7월 13일
@Stelios: Of course I do not publish my email address in the forum. You can try to compress the file or to crop the data. All we need is the class, size and the range of the values.
Sorry for the typo in "same". It was not too difficult to guess, that "save" was meant, was it?
Stelios Fanourakis
2018년 7월 13일
YOu can send me your email in private if you want to. Even the zip file has not much difference from the original in size. How do I crop the data?
Sorry for the typo in "same". It was not too difficult to guess, that "save" was meant, was it?
If that was the only command I would concentrate on, in order to solve my problem, yes, I might have figured it out. But at the same time, I am also looking for various solutions to other sites as well, plus, a bunch of different functions, so, it is rather exhausting to try to figure out typo errors that more experts in Matlab, than me, may do.
Stelios Fanourakis
2018년 7월 13일
I assume that the slice() function if properly written can do my job. Any suggestion?
Stelios Fanourakis
2018년 7월 13일
편집: Stelios Fanourakis
2018년 7월 13일
I was also thinking of using imfuse() to fuse the binary correctly translated images with the slices of the 4D image stack. How to use imfuse() for 4D images?
Rik
2018년 7월 13일
Your image is not binary, you have been told so repeatedly. Unless class(im2) returns logical, it is not a binary. Why do you ask people for help if you're not willing to accept their responses? If you keep frustrating the people that are trying to help you, you will end up with nobody to help you.
I think the best course of action for you is to follow a course on how to use Matlab, with a paid instructor.
Stelios Fanourakis
2018년 7월 13일
편집: Stelios Fanourakis
2018년 7월 13일
With the class(im2) I get ans = uint8.
Untill, I fix the display of the images, I may think several solutions to do it.
@Rik. Everybody, tells me that images are not binary (although, they appear so), and they may be right, I accept this but NOBODY will give me an actual solution.
I'd pay to get the solution. Do you have it?
Jan
2018년 7월 14일
tell me if GriddedInterpolant and or GridVectors turn an image to
binary format
u = unique(im2)
if isequal(u, [0, 1]) % Binary
answer = 'yes'
else
answer = 'no'
end
Stelios Fanourakis
2018년 7월 15일
편집: Stelios Fanourakis
2018년 7월 15일
@Jan. The answer to what you gave me is NO. But I am not sure if I can rely 100% on this since im2.mat that remained in my Workspace, by the time I applied that code was before the GriddedInterpolant implementation.
Let's move on. Shall we?
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?
참고 항목
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 (한국어)