imshow() displays a white image for a grey image












1














I have computed an image with values between 0 and 255. When I use imageview(), the image is correctly displayed, in grey levels, but when I want to save this image or display it with imshow, I have a white image, or sometimes some black pixels here and there:



image with imshow(), it appears the same when I save



Whereas with imageview():



enter image description here



Can some one help me?










share|improve this question


















  • 2




    i don't work with matlab but i have faced such problem once. Try to use imshow(uint8(image));
    – skm
    Mar 15 '14 at 19:56












  • My saviour! It works! Thank you
    – user3314570
    Mar 15 '14 at 20:00






  • 1




    if it worked, pls accept my answer :)
    – skm
    Mar 15 '14 at 20:05










  • @skm how do I accept? :)
    – user3314570
    Mar 16 '14 at 13:07










  • you have already accepted another answer...may be, juts "vote up" my answer by clicking the "up arrow" for my answer (not comment)
    – skm
    Mar 16 '14 at 14:44
















1














I have computed an image with values between 0 and 255. When I use imageview(), the image is correctly displayed, in grey levels, but when I want to save this image or display it with imshow, I have a white image, or sometimes some black pixels here and there:



image with imshow(), it appears the same when I save



Whereas with imageview():



enter image description here



Can some one help me?










share|improve this question


















  • 2




    i don't work with matlab but i have faced such problem once. Try to use imshow(uint8(image));
    – skm
    Mar 15 '14 at 19:56












  • My saviour! It works! Thank you
    – user3314570
    Mar 15 '14 at 20:00






  • 1




    if it worked, pls accept my answer :)
    – skm
    Mar 15 '14 at 20:05










  • @skm how do I accept? :)
    – user3314570
    Mar 16 '14 at 13:07










  • you have already accepted another answer...may be, juts "vote up" my answer by clicking the "up arrow" for my answer (not comment)
    – skm
    Mar 16 '14 at 14:44














1












1








1







I have computed an image with values between 0 and 255. When I use imageview(), the image is correctly displayed, in grey levels, but when I want to save this image or display it with imshow, I have a white image, or sometimes some black pixels here and there:



image with imshow(), it appears the same when I save



Whereas with imageview():



enter image description here



Can some one help me?










share|improve this question













I have computed an image with values between 0 and 255. When I use imageview(), the image is correctly displayed, in grey levels, but when I want to save this image or display it with imshow, I have a white image, or sometimes some black pixels here and there:



image with imshow(), it appears the same when I save



Whereas with imageview():



enter image description here



Can some one help me?







matlab imageview imshow






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 15 '14 at 19:52









user3314570

117112




117112








  • 2




    i don't work with matlab but i have faced such problem once. Try to use imshow(uint8(image));
    – skm
    Mar 15 '14 at 19:56












  • My saviour! It works! Thank you
    – user3314570
    Mar 15 '14 at 20:00






  • 1




    if it worked, pls accept my answer :)
    – skm
    Mar 15 '14 at 20:05










  • @skm how do I accept? :)
    – user3314570
    Mar 16 '14 at 13:07










  • you have already accepted another answer...may be, juts "vote up" my answer by clicking the "up arrow" for my answer (not comment)
    – skm
    Mar 16 '14 at 14:44














  • 2




    i don't work with matlab but i have faced such problem once. Try to use imshow(uint8(image));
    – skm
    Mar 15 '14 at 19:56












  • My saviour! It works! Thank you
    – user3314570
    Mar 15 '14 at 20:00






  • 1




    if it worked, pls accept my answer :)
    – skm
    Mar 15 '14 at 20:05










  • @skm how do I accept? :)
    – user3314570
    Mar 16 '14 at 13:07










  • you have already accepted another answer...may be, juts "vote up" my answer by clicking the "up arrow" for my answer (not comment)
    – skm
    Mar 16 '14 at 14:44








2




2




i don't work with matlab but i have faced such problem once. Try to use imshow(uint8(image));
– skm
Mar 15 '14 at 19:56






i don't work with matlab but i have faced such problem once. Try to use imshow(uint8(image));
– skm
Mar 15 '14 at 19:56














My saviour! It works! Thank you
– user3314570
Mar 15 '14 at 20:00




My saviour! It works! Thank you
– user3314570
Mar 15 '14 at 20:00




1




1




if it worked, pls accept my answer :)
– skm
Mar 15 '14 at 20:05




if it worked, pls accept my answer :)
– skm
Mar 15 '14 at 20:05












@skm how do I accept? :)
– user3314570
Mar 16 '14 at 13:07




@skm how do I accept? :)
– user3314570
Mar 16 '14 at 13:07












you have already accepted another answer...may be, juts "vote up" my answer by clicking the "up arrow" for my answer (not comment)
– skm
Mar 16 '14 at 14:44




you have already accepted another answer...may be, juts "vote up" my answer by clicking the "up arrow" for my answer (not comment)
– skm
Mar 16 '14 at 14:44












2 Answers
2






active

oldest

votes


















1














Matlab expects images of type double to be in the 0..1 range and images that are uint8 in the 0..255 range. You can convert the range yourself (but change values in the process), do an explicit cast (and potentially loose precision) or instruct Matlab to use the minimum and maximum value found in the image matrix as the white and black value to scale to when visualising.



See the following example with an uint8 image present in Matlab:



im = imread('moon.tif');
figure; imshow(im);
figure; imshow(double(im));
figure; imshow(double(im), );
figure; imshow(im2double(im));





share|improve this answer





























    3














    I think that you should use imshow(uint8(image)); on the image before displaying it.






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f22428938%2fimshow-displays-a-white-image-for-a-grey-image%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      Matlab expects images of type double to be in the 0..1 range and images that are uint8 in the 0..255 range. You can convert the range yourself (but change values in the process), do an explicit cast (and potentially loose precision) or instruct Matlab to use the minimum and maximum value found in the image matrix as the white and black value to scale to when visualising.



      See the following example with an uint8 image present in Matlab:



      im = imread('moon.tif');
      figure; imshow(im);
      figure; imshow(double(im));
      figure; imshow(double(im), );
      figure; imshow(im2double(im));





      share|improve this answer


























        1














        Matlab expects images of type double to be in the 0..1 range and images that are uint8 in the 0..255 range. You can convert the range yourself (but change values in the process), do an explicit cast (and potentially loose precision) or instruct Matlab to use the minimum and maximum value found in the image matrix as the white and black value to scale to when visualising.



        See the following example with an uint8 image present in Matlab:



        im = imread('moon.tif');
        figure; imshow(im);
        figure; imshow(double(im));
        figure; imshow(double(im), );
        figure; imshow(im2double(im));





        share|improve this answer
























          1












          1








          1






          Matlab expects images of type double to be in the 0..1 range and images that are uint8 in the 0..255 range. You can convert the range yourself (but change values in the process), do an explicit cast (and potentially loose precision) or instruct Matlab to use the minimum and maximum value found in the image matrix as the white and black value to scale to when visualising.



          See the following example with an uint8 image present in Matlab:



          im = imread('moon.tif');
          figure; imshow(im);
          figure; imshow(double(im));
          figure; imshow(double(im), );
          figure; imshow(im2double(im));





          share|improve this answer












          Matlab expects images of type double to be in the 0..1 range and images that are uint8 in the 0..255 range. You can convert the range yourself (but change values in the process), do an explicit cast (and potentially loose precision) or instruct Matlab to use the minimum and maximum value found in the image matrix as the white and black value to scale to when visualising.



          See the following example with an uint8 image present in Matlab:



          im = imread('moon.tif');
          figure; imshow(im);
          figure; imshow(double(im));
          figure; imshow(double(im), );
          figure; imshow(im2double(im));






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 15 '14 at 22:20









          Maurits

          1,83932330




          1,83932330

























              3














              I think that you should use imshow(uint8(image)); on the image before displaying it.






              share|improve this answer




























                3














                I think that you should use imshow(uint8(image)); on the image before displaying it.






                share|improve this answer


























                  3












                  3








                  3






                  I think that you should use imshow(uint8(image)); on the image before displaying it.






                  share|improve this answer














                  I think that you should use imshow(uint8(image)); on the image before displaying it.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 15 '14 at 20:07

























                  answered Mar 15 '14 at 19:54









                  skm

                  2,60142560




                  2,60142560






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f22428938%2fimshow-displays-a-white-image-for-a-grey-image%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      What visual should I use to simply compare current year value vs last year in Power BI desktop

                      How to ignore python UserWarning in pytest?

                      Alexandru Averescu