How matplotlib.pyplot.imshow deal with over 255 pixel value magically? [duplicate]












0
















This question already has an answer here:




  • matplotlib imshow - default colour normalisation

    1 answer



  • Matplotlib : What is the function of cmap in imshow?

    1 answer




Recently I've been working with matplotlib to deal with image.



And I found one thing interesting is that "matplotlib.pyplot.imshow" seems to work



the issue out magically that if you have pixel value more than 255 which in opencv with function



imshow would completely be mess up the image



Here's what I try:



import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt
img=cv.imread("image1.jpg",cv.IMREAD_GRAYSCALE)
img
array([[ 69, 69, 68, ..., 191, 184, 180],
[ 65, 65, 65, ..., 197, 191, 188],
[ 61, 61, 62, ..., 200, 197, 195],
...,
[ 75, 73, 73, ..., 96, 88, 65],
[ 84, 80, 76, ..., 145, 135, 111],
[ 90, 82, 73, ..., 216, 215, 217]], dtype=uint8)
img=img.astype(np.int32)
img+=500
plt.imshow(img, cmap="gray")
plt.show()
>>>img
array([[567, 567, 566, ..., 689, 682, 678],
[563, 563, 563, ..., 695, 689, 686],
[559, 559, 560, ..., 698, 695, 693],
...,
[573, 571, 571, ..., 594, 586, 563],
[582, 578, 574, ..., 643, 633, 609],
[588, 580, 571, ..., 714, 713, 715]], dtype=int32)


At the end ,you can find out that the array actually is not changed



but it gives the perfectly original image



I wonder how they deal with this problem,Thanks in advance!










share|improve this question













marked as duplicate by Matthieu Brucher, ImportanceOfBeingErnest matplotlib
Users with the  matplotlib badge can single-handedly close matplotlib questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 15 '18 at 14:34


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.























    0
















    This question already has an answer here:




    • matplotlib imshow - default colour normalisation

      1 answer



    • Matplotlib : What is the function of cmap in imshow?

      1 answer




    Recently I've been working with matplotlib to deal with image.



    And I found one thing interesting is that "matplotlib.pyplot.imshow" seems to work



    the issue out magically that if you have pixel value more than 255 which in opencv with function



    imshow would completely be mess up the image



    Here's what I try:



    import cv2 as cv
    import numpy as np
    import matplotlib.pyplot as plt
    img=cv.imread("image1.jpg",cv.IMREAD_GRAYSCALE)
    img
    array([[ 69, 69, 68, ..., 191, 184, 180],
    [ 65, 65, 65, ..., 197, 191, 188],
    [ 61, 61, 62, ..., 200, 197, 195],
    ...,
    [ 75, 73, 73, ..., 96, 88, 65],
    [ 84, 80, 76, ..., 145, 135, 111],
    [ 90, 82, 73, ..., 216, 215, 217]], dtype=uint8)
    img=img.astype(np.int32)
    img+=500
    plt.imshow(img, cmap="gray")
    plt.show()
    >>>img
    array([[567, 567, 566, ..., 689, 682, 678],
    [563, 563, 563, ..., 695, 689, 686],
    [559, 559, 560, ..., 698, 695, 693],
    ...,
    [573, 571, 571, ..., 594, 586, 563],
    [582, 578, 574, ..., 643, 633, 609],
    [588, 580, 571, ..., 714, 713, 715]], dtype=int32)


    At the end ,you can find out that the array actually is not changed



    but it gives the perfectly original image



    I wonder how they deal with this problem,Thanks in advance!










    share|improve this question













    marked as duplicate by Matthieu Brucher, ImportanceOfBeingErnest matplotlib
    Users with the  matplotlib badge can single-handedly close matplotlib questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Nov 15 '18 at 14:34


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





















      0












      0








      0


      0







      This question already has an answer here:




      • matplotlib imshow - default colour normalisation

        1 answer



      • Matplotlib : What is the function of cmap in imshow?

        1 answer




      Recently I've been working with matplotlib to deal with image.



      And I found one thing interesting is that "matplotlib.pyplot.imshow" seems to work



      the issue out magically that if you have pixel value more than 255 which in opencv with function



      imshow would completely be mess up the image



      Here's what I try:



      import cv2 as cv
      import numpy as np
      import matplotlib.pyplot as plt
      img=cv.imread("image1.jpg",cv.IMREAD_GRAYSCALE)
      img
      array([[ 69, 69, 68, ..., 191, 184, 180],
      [ 65, 65, 65, ..., 197, 191, 188],
      [ 61, 61, 62, ..., 200, 197, 195],
      ...,
      [ 75, 73, 73, ..., 96, 88, 65],
      [ 84, 80, 76, ..., 145, 135, 111],
      [ 90, 82, 73, ..., 216, 215, 217]], dtype=uint8)
      img=img.astype(np.int32)
      img+=500
      plt.imshow(img, cmap="gray")
      plt.show()
      >>>img
      array([[567, 567, 566, ..., 689, 682, 678],
      [563, 563, 563, ..., 695, 689, 686],
      [559, 559, 560, ..., 698, 695, 693],
      ...,
      [573, 571, 571, ..., 594, 586, 563],
      [582, 578, 574, ..., 643, 633, 609],
      [588, 580, 571, ..., 714, 713, 715]], dtype=int32)


      At the end ,you can find out that the array actually is not changed



      but it gives the perfectly original image



      I wonder how they deal with this problem,Thanks in advance!










      share|improve this question















      This question already has an answer here:




      • matplotlib imshow - default colour normalisation

        1 answer



      • Matplotlib : What is the function of cmap in imshow?

        1 answer




      Recently I've been working with matplotlib to deal with image.



      And I found one thing interesting is that "matplotlib.pyplot.imshow" seems to work



      the issue out magically that if you have pixel value more than 255 which in opencv with function



      imshow would completely be mess up the image



      Here's what I try:



      import cv2 as cv
      import numpy as np
      import matplotlib.pyplot as plt
      img=cv.imread("image1.jpg",cv.IMREAD_GRAYSCALE)
      img
      array([[ 69, 69, 68, ..., 191, 184, 180],
      [ 65, 65, 65, ..., 197, 191, 188],
      [ 61, 61, 62, ..., 200, 197, 195],
      ...,
      [ 75, 73, 73, ..., 96, 88, 65],
      [ 84, 80, 76, ..., 145, 135, 111],
      [ 90, 82, 73, ..., 216, 215, 217]], dtype=uint8)
      img=img.astype(np.int32)
      img+=500
      plt.imshow(img, cmap="gray")
      plt.show()
      >>>img
      array([[567, 567, 566, ..., 689, 682, 678],
      [563, 563, 563, ..., 695, 689, 686],
      [559, 559, 560, ..., 698, 695, 693],
      ...,
      [573, 571, 571, ..., 594, 586, 563],
      [582, 578, 574, ..., 643, 633, 609],
      [588, 580, 571, ..., 714, 713, 715]], dtype=int32)


      At the end ,you can find out that the array actually is not changed



      but it gives the perfectly original image



      I wonder how they deal with this problem,Thanks in advance!





      This question already has an answer here:




      • matplotlib imshow - default colour normalisation

        1 answer



      • Matplotlib : What is the function of cmap in imshow?

        1 answer








      python opencv matplotlib overflow






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 11:44









      kriskris

      345




      345




      marked as duplicate by Matthieu Brucher, ImportanceOfBeingErnest matplotlib
      Users with the  matplotlib badge can single-handedly close matplotlib questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 15 '18 at 14:34


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by Matthieu Brucher, ImportanceOfBeingErnest matplotlib
      Users with the  matplotlib badge can single-handedly close matplotlib questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 15 '18 at 14:34


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          0






          active

          oldest

          votes

















          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes

          Popular posts from this blog

          Bressuire

          Vorschmack

          Quarantine