How to make Image data to 2-D distribution plot?












-2















How to make Image data to 2-D distribution plot ?
I want to visualize image date to 2-dimensional distribution.
Is this possible ?



Image like MNIST : enter image description here



2D distribution like this :enter image description here










share|improve this question























  • what is exactly P(x) and Q(x)?

    – M. Doosti Lakhani
    Nov 17 '18 at 14:36











  • @M.DoostiLakhani That image is just show 2-d distribution. P(x) or Q(x) doesn't matter.I just want to plot MNIST data to 2D dist.

    – Nazzzz
    Nov 18 '18 at 1:05


















-2















How to make Image data to 2-D distribution plot ?
I want to visualize image date to 2-dimensional distribution.
Is this possible ?



Image like MNIST : enter image description here



2D distribution like this :enter image description here










share|improve this question























  • what is exactly P(x) and Q(x)?

    – M. Doosti Lakhani
    Nov 17 '18 at 14:36











  • @M.DoostiLakhani That image is just show 2-d distribution. P(x) or Q(x) doesn't matter.I just want to plot MNIST data to 2D dist.

    – Nazzzz
    Nov 18 '18 at 1:05
















-2












-2








-2








How to make Image data to 2-D distribution plot ?
I want to visualize image date to 2-dimensional distribution.
Is this possible ?



Image like MNIST : enter image description here



2D distribution like this :enter image description here










share|improve this question














How to make Image data to 2-D distribution plot ?
I want to visualize image date to 2-dimensional distribution.
Is this possible ?



Image like MNIST : enter image description here



2D distribution like this :enter image description here







deep-learning






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 17 '18 at 13:51









NazzzzNazzzz

54




54













  • what is exactly P(x) and Q(x)?

    – M. Doosti Lakhani
    Nov 17 '18 at 14:36











  • @M.DoostiLakhani That image is just show 2-d distribution. P(x) or Q(x) doesn't matter.I just want to plot MNIST data to 2D dist.

    – Nazzzz
    Nov 18 '18 at 1:05





















  • what is exactly P(x) and Q(x)?

    – M. Doosti Lakhani
    Nov 17 '18 at 14:36











  • @M.DoostiLakhani That image is just show 2-d distribution. P(x) or Q(x) doesn't matter.I just want to plot MNIST data to 2D dist.

    – Nazzzz
    Nov 18 '18 at 1:05



















what is exactly P(x) and Q(x)?

– M. Doosti Lakhani
Nov 17 '18 at 14:36





what is exactly P(x) and Q(x)?

– M. Doosti Lakhani
Nov 17 '18 at 14:36













@M.DoostiLakhani That image is just show 2-d distribution. P(x) or Q(x) doesn't matter.I just want to plot MNIST data to 2D dist.

– Nazzzz
Nov 18 '18 at 1:05







@M.DoostiLakhani That image is just show 2-d distribution. P(x) or Q(x) doesn't matter.I just want to plot MNIST data to 2D dist.

– Nazzzz
Nov 18 '18 at 1:05














1 Answer
1






active

oldest

votes


















0














About mnist, it does not mean anything I think. Because you have one channel of binary image so you have only zero or one. So you cannot have any plot like that.



But if you have grayscale image or colored image, you can do this:

source image:
source



import cv2
from matplotlib import pyplot as plt

img = cv2.imread('img.jpg', -1)
cv2.imshow('image',img)

color = ('b','g','r')
for channel,col in enumerate(color):
histr = cv2.calcHist([img],[channel],None,[256],[0,256])
plt.plot(histr,color = col)
plt.xlim([0,256])
plt.title('Histogram for color scale picture')
plt.show()

cv2.destroyAllWindows()


3-channel cv2



And if your image is grayscale:



# 1 channel image - grayscale
import cv2
from matplotlib import pyplot as plt

gray_img = cv2.imread('mnist.png')
cv2.imshow('image',gray_img)
hist = cv2.calcHist([gray_img],[0],None,[256],[0,256])
plt.hist(gray_img.ravel(),256,[0,256])
plt.title('Histogram for gray scale picture')
plt.show()

cv2.destroyAllWindows()


grayscale cv2



And the matplotlib way is:



import matplotlib.image as mpimg
from matplotlib import pyplot as plt

img=mpimg.imread('img.jpg')
imgplot = plt.imshow(img)
plt.hist(img.ravel(), bins=256, fc='k', ec='k')


matplotlib






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%2f53351852%2fhow-to-make-image-data-to-2-d-distribution-plot%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    About mnist, it does not mean anything I think. Because you have one channel of binary image so you have only zero or one. So you cannot have any plot like that.



    But if you have grayscale image or colored image, you can do this:

    source image:
    source



    import cv2
    from matplotlib import pyplot as plt

    img = cv2.imread('img.jpg', -1)
    cv2.imshow('image',img)

    color = ('b','g','r')
    for channel,col in enumerate(color):
    histr = cv2.calcHist([img],[channel],None,[256],[0,256])
    plt.plot(histr,color = col)
    plt.xlim([0,256])
    plt.title('Histogram for color scale picture')
    plt.show()

    cv2.destroyAllWindows()


    3-channel cv2



    And if your image is grayscale:



    # 1 channel image - grayscale
    import cv2
    from matplotlib import pyplot as plt

    gray_img = cv2.imread('mnist.png')
    cv2.imshow('image',gray_img)
    hist = cv2.calcHist([gray_img],[0],None,[256],[0,256])
    plt.hist(gray_img.ravel(),256,[0,256])
    plt.title('Histogram for gray scale picture')
    plt.show()

    cv2.destroyAllWindows()


    grayscale cv2



    And the matplotlib way is:



    import matplotlib.image as mpimg
    from matplotlib import pyplot as plt

    img=mpimg.imread('img.jpg')
    imgplot = plt.imshow(img)
    plt.hist(img.ravel(), bins=256, fc='k', ec='k')


    matplotlib






    share|improve this answer




























      0














      About mnist, it does not mean anything I think. Because you have one channel of binary image so you have only zero or one. So you cannot have any plot like that.



      But if you have grayscale image or colored image, you can do this:

      source image:
      source



      import cv2
      from matplotlib import pyplot as plt

      img = cv2.imread('img.jpg', -1)
      cv2.imshow('image',img)

      color = ('b','g','r')
      for channel,col in enumerate(color):
      histr = cv2.calcHist([img],[channel],None,[256],[0,256])
      plt.plot(histr,color = col)
      plt.xlim([0,256])
      plt.title('Histogram for color scale picture')
      plt.show()

      cv2.destroyAllWindows()


      3-channel cv2



      And if your image is grayscale:



      # 1 channel image - grayscale
      import cv2
      from matplotlib import pyplot as plt

      gray_img = cv2.imread('mnist.png')
      cv2.imshow('image',gray_img)
      hist = cv2.calcHist([gray_img],[0],None,[256],[0,256])
      plt.hist(gray_img.ravel(),256,[0,256])
      plt.title('Histogram for gray scale picture')
      plt.show()

      cv2.destroyAllWindows()


      grayscale cv2



      And the matplotlib way is:



      import matplotlib.image as mpimg
      from matplotlib import pyplot as plt

      img=mpimg.imread('img.jpg')
      imgplot = plt.imshow(img)
      plt.hist(img.ravel(), bins=256, fc='k', ec='k')


      matplotlib






      share|improve this answer


























        0












        0








        0







        About mnist, it does not mean anything I think. Because you have one channel of binary image so you have only zero or one. So you cannot have any plot like that.



        But if you have grayscale image or colored image, you can do this:

        source image:
        source



        import cv2
        from matplotlib import pyplot as plt

        img = cv2.imread('img.jpg', -1)
        cv2.imshow('image',img)

        color = ('b','g','r')
        for channel,col in enumerate(color):
        histr = cv2.calcHist([img],[channel],None,[256],[0,256])
        plt.plot(histr,color = col)
        plt.xlim([0,256])
        plt.title('Histogram for color scale picture')
        plt.show()

        cv2.destroyAllWindows()


        3-channel cv2



        And if your image is grayscale:



        # 1 channel image - grayscale
        import cv2
        from matplotlib import pyplot as plt

        gray_img = cv2.imread('mnist.png')
        cv2.imshow('image',gray_img)
        hist = cv2.calcHist([gray_img],[0],None,[256],[0,256])
        plt.hist(gray_img.ravel(),256,[0,256])
        plt.title('Histogram for gray scale picture')
        plt.show()

        cv2.destroyAllWindows()


        grayscale cv2



        And the matplotlib way is:



        import matplotlib.image as mpimg
        from matplotlib import pyplot as plt

        img=mpimg.imread('img.jpg')
        imgplot = plt.imshow(img)
        plt.hist(img.ravel(), bins=256, fc='k', ec='k')


        matplotlib






        share|improve this answer













        About mnist, it does not mean anything I think. Because you have one channel of binary image so you have only zero or one. So you cannot have any plot like that.



        But if you have grayscale image or colored image, you can do this:

        source image:
        source



        import cv2
        from matplotlib import pyplot as plt

        img = cv2.imread('img.jpg', -1)
        cv2.imshow('image',img)

        color = ('b','g','r')
        for channel,col in enumerate(color):
        histr = cv2.calcHist([img],[channel],None,[256],[0,256])
        plt.plot(histr,color = col)
        plt.xlim([0,256])
        plt.title('Histogram for color scale picture')
        plt.show()

        cv2.destroyAllWindows()


        3-channel cv2



        And if your image is grayscale:



        # 1 channel image - grayscale
        import cv2
        from matplotlib import pyplot as plt

        gray_img = cv2.imread('mnist.png')
        cv2.imshow('image',gray_img)
        hist = cv2.calcHist([gray_img],[0],None,[256],[0,256])
        plt.hist(gray_img.ravel(),256,[0,256])
        plt.title('Histogram for gray scale picture')
        plt.show()

        cv2.destroyAllWindows()


        grayscale cv2



        And the matplotlib way is:



        import matplotlib.image as mpimg
        from matplotlib import pyplot as plt

        img=mpimg.imread('img.jpg')
        imgplot = plt.imshow(img)
        plt.hist(img.ravel(), bins=256, fc='k', ec='k')


        matplotlib







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 18 '18 at 9:47









        M. Doosti LakhaniM. Doosti Lakhani

        334417




        334417






























            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53351852%2fhow-to-make-image-data-to-2-d-distribution-plot%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







            這個網誌中的熱門文章

            Tangent Lines Diagram Along Smooth Curve

            Yusuf al-Mu'taman ibn Hud

            Zucchini