Does anyone know why the images appear that way?
Show older comments
The shifted slight translation you'll see in the three plots is correct but why do they appear black and white (duotone)?
They should appear normal grayscale DICOM images. Any idea why this is happening?
I use imtranslate, griddedInterpolant and GridVectors for the translation
14 Comments
Anton Semechko
on 6 Jul 2018
That will happen in the image has a non-integer format (e.g., double). Try visualizing the image using command
imshow(im,[])
and see if it makes a difference.
Stelios Fanourakis
on 6 Jul 2018
Anton Semechko
on 6 Jul 2018
I am assuming you were using 'griddedInterpolant' to resample your 3D image (IM). In which case, resampled image (IM2) will be different from IM. The points at which (IM) is being resampled, do any of them fall outside the domain of IM? This is easy to check, because
sum(isnan(IM2(:)))>0
will be true.
Are you sure you are not seeing the true values of the image? What is the result of doing
>> numel(unique(im(:))
Stelios Fanourakis
on 6 Jul 2018
Stelios Fanourakis
on 6 Jul 2018
Stelios Fanourakis
on 6 Jul 2018
Image Analyst
on 6 Jul 2018
I don't see three plots. I see 4 images, at least what I think are images - I guess then could be plots if you used bar() and patch() or something. The lower right image is a surface rendering of a 3-D image volume. Where are the plots?
And post an image of what the normal (not "duotone") images should look like.
Stelios Fanourakis
on 6 Jul 2018
Matt J
on 6 Jul 2018
Well, we need to have some data and code. Please show the lines of code that are displaying the image slices. Also, please attach those particular slices as matrices in a .mat file.
Jan
on 11 Jul 2018
I already use imshow and the uint8() command to bring it back from double
Do you mean:
imgUINT8 = uint8(imgDOUBLE * 255)
? Or did you omit the scaling?
Stelios Fanourakis
on 11 Jul 2018
@Stelios: Do you see the problem? You have posted "use imshow and the uint8() command" and only by bold guessing, what this could mean, a substantial problem has been found. Please, Stelios, care for posting the required details, most of all the relevant part of the code.
"I still get a wrong outcome" does not allow to help you. We cannot read your mind or guess, which detail is wrong or what you consider to be right.
The new screenshots look much more like something I'd expect. So I think your former code to convert between double and uint8 contained a bug. Maybe there is another bug also.
Stelios Fanourakis
on 12 Jul 2018
Answers (4)
im(~isfinite(im))=0;
Then reload the resulting im to the viewer.
Image Analyst
on 7 Jul 2018
No, you didn't try Anton's suggestion because you said "I already use imshow and the uint8() command to bring it back from double. " Well sorry but that won't correct the problem. You have a double image, and imshow() without any [] expects that the range of the image will be between 0 and 1. Anything less than 0 will show up as black and anything more than 1 will show up as white. Your data is fine and good, it's just not being displayed properly. Why don't you at least try to show it with []. Please just humor us and try it:
maxValue = max(im(:)) % Don't use a semicolon
maxValue = min(im(:)) % Don't use a semicolon
imshow(im, []);
What does it show in the command window for the max and min? And do the images now look good? If not, save the image to a .mat file and attach it with the paper clip icon.
13 Comments
Stelios Fanourakis
on 7 Jul 2018
Edited: Matt J
on 7 Jul 2018
Stelios Fanourakis
on 7 Jul 2018
Matt J
on 7 Jul 2018
did you normalize the data to the range 0 to 255 before converting to uint8?
Stelios Fanourakis
on 7 Jul 2018
Image Analyst
on 7 Jul 2018
Try this:
figure;
histogram(im);
figure;
im = mat2gray(im);
Whether mat2gray() works well depends on your distribution since it scales the min to 0 and the max to 1, but if you have a real outlier, it would squish the resulting image into a narrow range so that's why I wanted to check the histogram first. Post a screenshot of the histogram.
Stelios Fanourakis
on 7 Jul 2018
Stelios Fanourakis
on 7 Jul 2018
Image Analyst
on 7 Jul 2018
Your data distribution is really wacky. The scaled version is not all zeros but you just can't see it because almost all the pixels are very very close to the minimum value and you have the largest value that is way, way brighter than most of your pixels. I suggest you use imadjust() if you want to see it look nice.
imshow(imadjust(im));
If you want you can specify a fraction of the histogram tails you want to come in on rather than the default of 1%. From the help:
J = imadjust(I) maps the intensity values in grayscale image I to new values in J. By default, imadjust saturates the bottom 1% and the top 1% of all pixel values. This operation increases the contrast of the output image J.
Stelios Fanourakis
on 7 Jul 2018
Matt J
on 7 Jul 2018
I don't really see why the histogram would change simply by converting to double...
Stelios Fanourakis
on 15 Jul 2018
Stelios Fanourakis
on 7 Jul 2018
Edited: Image Analyst
on 7 Jul 2018
0 votes
12 Comments
Image Analyst
on 7 Jul 2018
No. You just totally don't understand how images are displayed. I tried to explain it to you but I guess I didn't do a good job. You can display your data both with range scaling and/or type conversion or without - you just have to do it correctly.
Why don't you just attach your array variable in a .mat file and I'll make a little demo for you?
Stelios Fanourakis
on 8 Jul 2018
Matt J
on 8 Jul 2018
In any case, if your histogram really did change after conversion to double, I think we've answered your question about whether imtranslate, griddedInterpolant or any other transformations afterward were responsible - probably not. Clearly something strange happened in your conversion to double because, as I'm sure you must understand, such a conversion should not change the histogram.
Stelios Fanourakis
on 8 Jul 2018
Image Analyst
on 8 Jul 2018
I know what the problem is. Matt knows what the problem is. Anton knows what the problem is. I'm about to give up even trying to explain it to you because after so many replies back and forth you still won't attach your data.
You gave code above. Do you think we can run it? No. We can't. Why not? You're not giving us 'imgpositions.txt'. Maybe it's secret or proprietary - I don't know - but that's fine if it is. Good luck though.
Stelios Fanourakis
on 8 Jul 2018
Image Analyst
on 8 Jul 2018
Your code doesn't run. In your code you gave above, what is im2?
t = im2double(im2)/255
Is that the old name of a variable that you renamed? Or the name of a variable created in the base workspace by another m-file?
Perhaps you should call "clear all" or "clearvars" and then try to run your code. Then give us the fixed code where it creates im2.
Stelios Fanourakis
on 8 Jul 2018
Stelios Fanourakis
on 8 Jul 2018
Stelios Fanourakis
on 9 Jul 2018
Stelios Fanourakis
on 11 Jul 2018
Stelios Fanourakis
on 15 Jul 2018
Categories
Find more on Matrix Indexing 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!