Visualizing RGB bands of RGBN image












0















I have an RGBN band .tif satellite image of PlanetScope which I would like to preprocess for a neural network. When I view the image in QGIS I get a nice RGB image, however when importing as a numpy array the image is very light. Some information on the image:



Type of the image :  <class 'numpy.ndarray'>

Shape of the image : (7327, 7327, 5)
Image Height 7327
Image Width 7327
Image Shape (7327, 7327, 5)
Dimension of Image 3
Image size 268424645
Maximum RGB value in this image 65535
Minimum RGB value in this image 1


The image is uint16 type. The last band (pic[:,:,5]) only shows a singular value (65535) in all instances. Hence, I think this band should be removed leaving the RGBN bands, of which the information is as follows:



Type of the image :  <class 'numpy.ndarray'>

Shape of the image : (7327, 7327, 4)
Image Height 7327
Image Width 7327
Image Shape (7327, 7327, 4)
Dimension of Image 3
Image size 214739716
Maximum RGB value in this image 19382
Minimum RGB value in this image 1


The maximum value (19382) of the RGBN image seems pretty low knowing that the range of uint16 images is 0-65535. Subsequently the function 'skimage.io.imshow(image)' shows a nearly white image. I do not understand why QGIS is able to show the image properly in real color but python does not.



The image is loaded by means of pic = skimage.io.imread("planetscope_20180502_43.tif")



I have tried scaling the image with img_scaled = pic / pic.max() and converting it to uint8 before viewing the image with img_as_ubyte(pic) without success. I view the image with skimage.io.imshow(pic).



If necessary the image can be downloaded here. I incorporate the image because somehow it seems not possible to import the image using certain packages (Tifffile for example does not work on this tif file).










share|improve this question

























  • Some minimal code that you used to load the image, please. Also – while you are editing that in –, just one question at a time. (I would recommend to remove the "Furthermore …. very broad discussion" part, but suit yourself.)

    – usr2564301
    Nov 26 '18 at 13:16













  • Thanks for your reply, I have edited the original question! If there is more information missing please let me know.

    – Eeuwigestudent1
    Nov 26 '18 at 13:44













  • Please edit your question title to be more indicative of what the question is about — you’ll likely get more visitors to your question. “Image processing” is very generic and is also the name of one of your tags. Try to come up with a title that doesn’t duplicate info from the tags.

    – Cris Luengo
    Nov 26 '18 at 15:04











  • Title is edited, I will keep your suggestions in mind for future posts as well.

    – Eeuwigestudent1
    Nov 26 '18 at 15:10
















0















I have an RGBN band .tif satellite image of PlanetScope which I would like to preprocess for a neural network. When I view the image in QGIS I get a nice RGB image, however when importing as a numpy array the image is very light. Some information on the image:



Type of the image :  <class 'numpy.ndarray'>

Shape of the image : (7327, 7327, 5)
Image Height 7327
Image Width 7327
Image Shape (7327, 7327, 5)
Dimension of Image 3
Image size 268424645
Maximum RGB value in this image 65535
Minimum RGB value in this image 1


The image is uint16 type. The last band (pic[:,:,5]) only shows a singular value (65535) in all instances. Hence, I think this band should be removed leaving the RGBN bands, of which the information is as follows:



Type of the image :  <class 'numpy.ndarray'>

Shape of the image : (7327, 7327, 4)
Image Height 7327
Image Width 7327
Image Shape (7327, 7327, 4)
Dimension of Image 3
Image size 214739716
Maximum RGB value in this image 19382
Minimum RGB value in this image 1


The maximum value (19382) of the RGBN image seems pretty low knowing that the range of uint16 images is 0-65535. Subsequently the function 'skimage.io.imshow(image)' shows a nearly white image. I do not understand why QGIS is able to show the image properly in real color but python does not.



The image is loaded by means of pic = skimage.io.imread("planetscope_20180502_43.tif")



I have tried scaling the image with img_scaled = pic / pic.max() and converting it to uint8 before viewing the image with img_as_ubyte(pic) without success. I view the image with skimage.io.imshow(pic).



If necessary the image can be downloaded here. I incorporate the image because somehow it seems not possible to import the image using certain packages (Tifffile for example does not work on this tif file).










share|improve this question

























  • Some minimal code that you used to load the image, please. Also – while you are editing that in –, just one question at a time. (I would recommend to remove the "Furthermore …. very broad discussion" part, but suit yourself.)

    – usr2564301
    Nov 26 '18 at 13:16













  • Thanks for your reply, I have edited the original question! If there is more information missing please let me know.

    – Eeuwigestudent1
    Nov 26 '18 at 13:44













  • Please edit your question title to be more indicative of what the question is about — you’ll likely get more visitors to your question. “Image processing” is very generic and is also the name of one of your tags. Try to come up with a title that doesn’t duplicate info from the tags.

    – Cris Luengo
    Nov 26 '18 at 15:04











  • Title is edited, I will keep your suggestions in mind for future posts as well.

    – Eeuwigestudent1
    Nov 26 '18 at 15:10














0












0








0








I have an RGBN band .tif satellite image of PlanetScope which I would like to preprocess for a neural network. When I view the image in QGIS I get a nice RGB image, however when importing as a numpy array the image is very light. Some information on the image:



Type of the image :  <class 'numpy.ndarray'>

Shape of the image : (7327, 7327, 5)
Image Height 7327
Image Width 7327
Image Shape (7327, 7327, 5)
Dimension of Image 3
Image size 268424645
Maximum RGB value in this image 65535
Minimum RGB value in this image 1


The image is uint16 type. The last band (pic[:,:,5]) only shows a singular value (65535) in all instances. Hence, I think this band should be removed leaving the RGBN bands, of which the information is as follows:



Type of the image :  <class 'numpy.ndarray'>

Shape of the image : (7327, 7327, 4)
Image Height 7327
Image Width 7327
Image Shape (7327, 7327, 4)
Dimension of Image 3
Image size 214739716
Maximum RGB value in this image 19382
Minimum RGB value in this image 1


The maximum value (19382) of the RGBN image seems pretty low knowing that the range of uint16 images is 0-65535. Subsequently the function 'skimage.io.imshow(image)' shows a nearly white image. I do not understand why QGIS is able to show the image properly in real color but python does not.



The image is loaded by means of pic = skimage.io.imread("planetscope_20180502_43.tif")



I have tried scaling the image with img_scaled = pic / pic.max() and converting it to uint8 before viewing the image with img_as_ubyte(pic) without success. I view the image with skimage.io.imshow(pic).



If necessary the image can be downloaded here. I incorporate the image because somehow it seems not possible to import the image using certain packages (Tifffile for example does not work on this tif file).










share|improve this question
















I have an RGBN band .tif satellite image of PlanetScope which I would like to preprocess for a neural network. When I view the image in QGIS I get a nice RGB image, however when importing as a numpy array the image is very light. Some information on the image:



Type of the image :  <class 'numpy.ndarray'>

Shape of the image : (7327, 7327, 5)
Image Height 7327
Image Width 7327
Image Shape (7327, 7327, 5)
Dimension of Image 3
Image size 268424645
Maximum RGB value in this image 65535
Minimum RGB value in this image 1


The image is uint16 type. The last band (pic[:,:,5]) only shows a singular value (65535) in all instances. Hence, I think this band should be removed leaving the RGBN bands, of which the information is as follows:



Type of the image :  <class 'numpy.ndarray'>

Shape of the image : (7327, 7327, 4)
Image Height 7327
Image Width 7327
Image Shape (7327, 7327, 4)
Dimension of Image 3
Image size 214739716
Maximum RGB value in this image 19382
Minimum RGB value in this image 1


The maximum value (19382) of the RGBN image seems pretty low knowing that the range of uint16 images is 0-65535. Subsequently the function 'skimage.io.imshow(image)' shows a nearly white image. I do not understand why QGIS is able to show the image properly in real color but python does not.



The image is loaded by means of pic = skimage.io.imread("planetscope_20180502_43.tif")



I have tried scaling the image with img_scaled = pic / pic.max() and converting it to uint8 before viewing the image with img_as_ubyte(pic) without success. I view the image with skimage.io.imshow(pic).



If necessary the image can be downloaded here. I incorporate the image because somehow it seems not possible to import the image using certain packages (Tifffile for example does not work on this tif file).







image-processing neural-network python-imaging-library rgb image-scaling






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 15:07







Eeuwigestudent1

















asked Nov 26 '18 at 12:42









Eeuwigestudent1Eeuwigestudent1

467




467













  • Some minimal code that you used to load the image, please. Also – while you are editing that in –, just one question at a time. (I would recommend to remove the "Furthermore …. very broad discussion" part, but suit yourself.)

    – usr2564301
    Nov 26 '18 at 13:16













  • Thanks for your reply, I have edited the original question! If there is more information missing please let me know.

    – Eeuwigestudent1
    Nov 26 '18 at 13:44













  • Please edit your question title to be more indicative of what the question is about — you’ll likely get more visitors to your question. “Image processing” is very generic and is also the name of one of your tags. Try to come up with a title that doesn’t duplicate info from the tags.

    – Cris Luengo
    Nov 26 '18 at 15:04











  • Title is edited, I will keep your suggestions in mind for future posts as well.

    – Eeuwigestudent1
    Nov 26 '18 at 15:10



















  • Some minimal code that you used to load the image, please. Also – while you are editing that in –, just one question at a time. (I would recommend to remove the "Furthermore …. very broad discussion" part, but suit yourself.)

    – usr2564301
    Nov 26 '18 at 13:16













  • Thanks for your reply, I have edited the original question! If there is more information missing please let me know.

    – Eeuwigestudent1
    Nov 26 '18 at 13:44













  • Please edit your question title to be more indicative of what the question is about — you’ll likely get more visitors to your question. “Image processing” is very generic and is also the name of one of your tags. Try to come up with a title that doesn’t duplicate info from the tags.

    – Cris Luengo
    Nov 26 '18 at 15:04











  • Title is edited, I will keep your suggestions in mind for future posts as well.

    – Eeuwigestudent1
    Nov 26 '18 at 15:10

















Some minimal code that you used to load the image, please. Also – while you are editing that in –, just one question at a time. (I would recommend to remove the "Furthermore …. very broad discussion" part, but suit yourself.)

– usr2564301
Nov 26 '18 at 13:16







Some minimal code that you used to load the image, please. Also – while you are editing that in –, just one question at a time. (I would recommend to remove the "Furthermore …. very broad discussion" part, but suit yourself.)

– usr2564301
Nov 26 '18 at 13:16















Thanks for your reply, I have edited the original question! If there is more information missing please let me know.

– Eeuwigestudent1
Nov 26 '18 at 13:44







Thanks for your reply, I have edited the original question! If there is more information missing please let me know.

– Eeuwigestudent1
Nov 26 '18 at 13:44















Please edit your question title to be more indicative of what the question is about — you’ll likely get more visitors to your question. “Image processing” is very generic and is also the name of one of your tags. Try to come up with a title that doesn’t duplicate info from the tags.

– Cris Luengo
Nov 26 '18 at 15:04





Please edit your question title to be more indicative of what the question is about — you’ll likely get more visitors to your question. “Image processing” is very generic and is also the name of one of your tags. Try to come up with a title that doesn’t duplicate info from the tags.

– Cris Luengo
Nov 26 '18 at 15:04













Title is edited, I will keep your suggestions in mind for future posts as well.

– Eeuwigestudent1
Nov 26 '18 at 15:10





Title is edited, I will keep your suggestions in mind for future posts as well.

– Eeuwigestudent1
Nov 26 '18 at 15:10












2 Answers
2






active

oldest

votes


















1














The max values of the RGB channels are lower than that of the N channel:



>>> pic.max(axis=(0,1))
array([10300, 7776, 11530, 19382, 65535], dtype=uint16)


But look at the mean values of the RGB channels: they are much smaller than max/2:



>>> pic.mean(axis=(0,1))
array([ 439.14001492, 593.17588875, 542.4638124 , 3604.6826063 ,
65535. ])


You have a high dynamic range (HDR) image here and want to compress its high range to 8 bits for displaying. A linear scaling with the maximum value won't do as the highest peaks are an order of magnitude higher than the average image values. Plotting the histogram of the RGB values:



Histogram of RGB data



If you do a linear scaling with some factor that's a bit above the mean and just disregard clipping the rest (now overexposed) values you can display it to see you have valid data:



rgb = pic[..., :3].astype(np.float32) / 2000
rgb = np.clip(rgb, 0.0, 1.0)


But to get a proper image, you will need to look into what the camera response of your data is, and how these HDR images are usually compressed into 8 bits for displaying (I'm not familiar with satellite imaging).






share|improve this answer































    0














    Thank you w-m, I was able to built on that and figured it out. Since w-m already did a neat job to elaborate on the problem, I will just leave the code here that I wrote to resolve the issue:



    for i in range(0,4):
    min_ = int(np.percentile(image[:,:,i],2))
    max_ = int(np.percentile(image[:,:,i],98))

    np.maximum(image[:,:,i])
    np.minimum(image[:,:,i])

    image[:,:,i] = np.interp(image[:,:,i], image[:,:,i].min(), image[:,:,i].max(), (0,255))

    image_8bit_scaled = skimage.img_as_ubyte(image)





    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%2f53481377%2fvisualizing-rgb-bands-of-rgbn-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














      The max values of the RGB channels are lower than that of the N channel:



      >>> pic.max(axis=(0,1))
      array([10300, 7776, 11530, 19382, 65535], dtype=uint16)


      But look at the mean values of the RGB channels: they are much smaller than max/2:



      >>> pic.mean(axis=(0,1))
      array([ 439.14001492, 593.17588875, 542.4638124 , 3604.6826063 ,
      65535. ])


      You have a high dynamic range (HDR) image here and want to compress its high range to 8 bits for displaying. A linear scaling with the maximum value won't do as the highest peaks are an order of magnitude higher than the average image values. Plotting the histogram of the RGB values:



      Histogram of RGB data



      If you do a linear scaling with some factor that's a bit above the mean and just disregard clipping the rest (now overexposed) values you can display it to see you have valid data:



      rgb = pic[..., :3].astype(np.float32) / 2000
      rgb = np.clip(rgb, 0.0, 1.0)


      But to get a proper image, you will need to look into what the camera response of your data is, and how these HDR images are usually compressed into 8 bits for displaying (I'm not familiar with satellite imaging).






      share|improve this answer




























        1














        The max values of the RGB channels are lower than that of the N channel:



        >>> pic.max(axis=(0,1))
        array([10300, 7776, 11530, 19382, 65535], dtype=uint16)


        But look at the mean values of the RGB channels: they are much smaller than max/2:



        >>> pic.mean(axis=(0,1))
        array([ 439.14001492, 593.17588875, 542.4638124 , 3604.6826063 ,
        65535. ])


        You have a high dynamic range (HDR) image here and want to compress its high range to 8 bits for displaying. A linear scaling with the maximum value won't do as the highest peaks are an order of magnitude higher than the average image values. Plotting the histogram of the RGB values:



        Histogram of RGB data



        If you do a linear scaling with some factor that's a bit above the mean and just disregard clipping the rest (now overexposed) values you can display it to see you have valid data:



        rgb = pic[..., :3].astype(np.float32) / 2000
        rgb = np.clip(rgb, 0.0, 1.0)


        But to get a proper image, you will need to look into what the camera response of your data is, and how these HDR images are usually compressed into 8 bits for displaying (I'm not familiar with satellite imaging).






        share|improve this answer


























          1












          1








          1







          The max values of the RGB channels are lower than that of the N channel:



          >>> pic.max(axis=(0,1))
          array([10300, 7776, 11530, 19382, 65535], dtype=uint16)


          But look at the mean values of the RGB channels: they are much smaller than max/2:



          >>> pic.mean(axis=(0,1))
          array([ 439.14001492, 593.17588875, 542.4638124 , 3604.6826063 ,
          65535. ])


          You have a high dynamic range (HDR) image here and want to compress its high range to 8 bits for displaying. A linear scaling with the maximum value won't do as the highest peaks are an order of magnitude higher than the average image values. Plotting the histogram of the RGB values:



          Histogram of RGB data



          If you do a linear scaling with some factor that's a bit above the mean and just disregard clipping the rest (now overexposed) values you can display it to see you have valid data:



          rgb = pic[..., :3].astype(np.float32) / 2000
          rgb = np.clip(rgb, 0.0, 1.0)


          But to get a proper image, you will need to look into what the camera response of your data is, and how these HDR images are usually compressed into 8 bits for displaying (I'm not familiar with satellite imaging).






          share|improve this answer













          The max values of the RGB channels are lower than that of the N channel:



          >>> pic.max(axis=(0,1))
          array([10300, 7776, 11530, 19382, 65535], dtype=uint16)


          But look at the mean values of the RGB channels: they are much smaller than max/2:



          >>> pic.mean(axis=(0,1))
          array([ 439.14001492, 593.17588875, 542.4638124 , 3604.6826063 ,
          65535. ])


          You have a high dynamic range (HDR) image here and want to compress its high range to 8 bits for displaying. A linear scaling with the maximum value won't do as the highest peaks are an order of magnitude higher than the average image values. Plotting the histogram of the RGB values:



          Histogram of RGB data



          If you do a linear scaling with some factor that's a bit above the mean and just disregard clipping the rest (now overexposed) values you can display it to see you have valid data:



          rgb = pic[..., :3].astype(np.float32) / 2000
          rgb = np.clip(rgb, 0.0, 1.0)


          But to get a proper image, you will need to look into what the camera response of your data is, and how these HDR images are usually compressed into 8 bits for displaying (I'm not familiar with satellite imaging).







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 27 '18 at 14:20









          w-mw-m

          6,5042434




          6,5042434

























              0














              Thank you w-m, I was able to built on that and figured it out. Since w-m already did a neat job to elaborate on the problem, I will just leave the code here that I wrote to resolve the issue:



              for i in range(0,4):
              min_ = int(np.percentile(image[:,:,i],2))
              max_ = int(np.percentile(image[:,:,i],98))

              np.maximum(image[:,:,i])
              np.minimum(image[:,:,i])

              image[:,:,i] = np.interp(image[:,:,i], image[:,:,i].min(), image[:,:,i].max(), (0,255))

              image_8bit_scaled = skimage.img_as_ubyte(image)





              share|improve this answer




























                0














                Thank you w-m, I was able to built on that and figured it out. Since w-m already did a neat job to elaborate on the problem, I will just leave the code here that I wrote to resolve the issue:



                for i in range(0,4):
                min_ = int(np.percentile(image[:,:,i],2))
                max_ = int(np.percentile(image[:,:,i],98))

                np.maximum(image[:,:,i])
                np.minimum(image[:,:,i])

                image[:,:,i] = np.interp(image[:,:,i], image[:,:,i].min(), image[:,:,i].max(), (0,255))

                image_8bit_scaled = skimage.img_as_ubyte(image)





                share|improve this answer


























                  0












                  0








                  0







                  Thank you w-m, I was able to built on that and figured it out. Since w-m already did a neat job to elaborate on the problem, I will just leave the code here that I wrote to resolve the issue:



                  for i in range(0,4):
                  min_ = int(np.percentile(image[:,:,i],2))
                  max_ = int(np.percentile(image[:,:,i],98))

                  np.maximum(image[:,:,i])
                  np.minimum(image[:,:,i])

                  image[:,:,i] = np.interp(image[:,:,i], image[:,:,i].min(), image[:,:,i].max(), (0,255))

                  image_8bit_scaled = skimage.img_as_ubyte(image)





                  share|improve this answer













                  Thank you w-m, I was able to built on that and figured it out. Since w-m already did a neat job to elaborate on the problem, I will just leave the code here that I wrote to resolve the issue:



                  for i in range(0,4):
                  min_ = int(np.percentile(image[:,:,i],2))
                  max_ = int(np.percentile(image[:,:,i],98))

                  np.maximum(image[:,:,i])
                  np.minimum(image[:,:,i])

                  image[:,:,i] = np.interp(image[:,:,i], image[:,:,i].min(), image[:,:,i].max(), (0,255))

                  image_8bit_scaled = skimage.img_as_ubyte(image)






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 28 '18 at 15:05









                  Eeuwigestudent1Eeuwigestudent1

                  467




                  467






























                      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%2f53481377%2fvisualizing-rgb-bands-of-rgbn-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

                      Tonle Sap (See)

                      I get strange results when I access the Sqlitedatabase with Unity C# via XAMPP

                      Guatemaltekische Davis-Cup-Mannschaft