GriddedInterpolant and GridVectors turn image to binary?
Afficher commentaires plus anciens
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 commentaires
Stephen23
le 8 Juil 2018
Duplicate:
https://www.mathworks.com/matlabcentral/answers/409120-does-anyone-know-why-the-images-appear-that-way
Stelios Fanourakis
le 8 Juil 2018
Guillaume
le 8 Juil 2018
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
le 8 Juil 2018
Modifié(e) : Stelios Fanourakis
le 8 Juil 2018
Guillaume
le 8 Juil 2018
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
le 8 Juil 2018
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
le 8 Juil 2018
Stelios Fanourakis
le 8 Juil 2018
Guillaume
le 8 Juil 2018
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
le 8 Juil 2018
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
le 8 Juil 2018
Stelios Fanourakis
le 8 Juil 2018
Stelios Fanourakis
le 8 Juil 2018
Modifié(e) : Stelios Fanourakis
le 8 Juil 2018
Jan
le 12 Juil 2018
@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
le 12 Juil 2018
Jan
le 12 Juil 2018
@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
le 12 Juil 2018
Modifié(e) : Stelios Fanourakis
le 12 Juil 2018
Réponses (3)
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.
Stelios Fanourakis
le 9 Juil 2018
0 votes
9 commentaires
Matt J
le 9 Juil 2018
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
le 9 Juil 2018
Matt J
le 9 Juil 2018
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
le 9 Juil 2018
Stelios Fanourakis
le 9 Juil 2018
Guillaume
le 9 Juil 2018
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
le 9 Juil 2018
Stelios Fanourakis
le 9 Juil 2018
Jan
le 12 Juil 2018
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
le 9 Juil 2018
0 votes
35 commentaires
What if you replace every occurrence of imshow(I) in your code with
med=median(I(:));
sig=std(I(:));
imshow(I,med+3*[-1,1]*sig);
Stelios Fanourakis
le 9 Juil 2018
Modifié(e) : Stelios Fanourakis
le 9 Juil 2018
Stelios Fanourakis
le 10 Juil 2018
Stelios Fanourakis
le 10 Juil 2018
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
le 10 Juil 2018
Stelios Fanourakis
le 10 Juil 2018
Stelios Fanourakis
le 10 Juil 2018
Guillaume
le 10 Juil 2018
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
le 10 Juil 2018
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
le 10 Juil 2018
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
le 10 Juil 2018
Stelios Fanourakis
le 11 Juil 2018
Stelios Fanourakis
le 11 Juil 2018
Modifié(e) : Stelios Fanourakis
le 11 Juil 2018
Stelios Fanourakis
le 11 Juil 2018
Jan
le 12 Juil 2018
@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
le 12 Juil 2018
Jan
le 12 Juil 2018
- 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
le 12 Juil 2018
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
le 12 Juil 2018
Modifié(e) : Stelios Fanourakis
le 12 Juil 2018
Rik
le 12 Juil 2018
I assume Jan made a typo. The line below should work.
save('im2.mat', 'im2')
Stelios Fanourakis
le 13 Juil 2018
Stelios Fanourakis
le 13 Juil 2018
Jan
le 13 Juil 2018
@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
le 13 Juil 2018
Stelios Fanourakis
le 13 Juil 2018
Stelios Fanourakis
le 13 Juil 2018
Modifié(e) : Stelios Fanourakis
le 13 Juil 2018
Rik
le 13 Juil 2018
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
le 13 Juil 2018
Modifié(e) : Stelios Fanourakis
le 13 Juil 2018
Jan
le 14 Juil 2018
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
le 15 Juil 2018
Modifié(e) : Stelios Fanourakis
le 15 Juil 2018
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!