Menu

Keyence .vk6 image format

2021-07-27
2025-02-07
  • serafin malyszew

    I was surprised to find out that Gwyddion handled .vk4 files as I've never seen any other open-source microscopy programs that worked with any of Keyence's file formats. How similar are .vk6 files to the .vk4 file extension? I could not find any documentation on the .vk6 files and there's no real information about it online. Could .vk6 file support be implemented in future releases of Gwyddion and does anyone know where to get any information about it?

    I am trying to find a way to convert .vk6 files into .jpeg through Python, but I am unsure of where to begin as there is so little information about it. Does anyone have any experience with converting .vk6 using ImageJ or Python?

    Thank you.

     
  • David Nečas

    David Nečas - 2021-07-27

    How similar are .vk6 files to the .vk4 file extension?

    I have no idea – I have never seen any vk6 file. Of course it is a key question. So please provide some files.

     
    • serafin malyszew

      Would it help if the image was of something specific or could I just take a picture of a piece of paper and share it with you? Would any of those factors matter in conducting analysis of the file format?
      Thank you for your help.

       
      • David Nečas

        David Nečas - 2021-07-28

        It does not matter for checking if the file structure resembles something we know and/or seems accessible to analysis (the VK4 format consists of large binary structs and is not easy to analyse, so I do not have extra high hopes…). It is always good to have some idea what data are in the file though – see also here.

         
  • David Nečas

    David Nečas - 2021-07-29

    Thanks for the file sample. It is definitely quite different. However, it is easy to begin picking it apart.

    It starts with a 7-byte header, V, K, 6, f, 0xc2, 0x01, 0x00 (not sure about the meaning of the last 3 bytes).

    Then there is an embedded Windows 3.x BMP file. You can easily extracting using the size specified in the BMP header.

    Immediately after that follows an embedded ZIP archive. It contains files

    • Vk4File – a VK4 file you can open in Gwyddion
    • Vk4MeasureCondition – some binary
    • VK6MeasureCondition – another ZIP file, containing some information in text files inside
    • Vk6ImageData – another ZIP file (they just love nesting files, don't they?), with some binary files inside; these seem to be mostly raw data, but I do not know the format yet

    I will not get to more analysis over the weekend now, but I am cautiously optimistic about implementation in Gwyddion. The structure is crazy, but apparently accessible to analysis.

     
    • serafin malyszew

      That's incredible, I had no idea this information could be extracted from it. Is there anything that I can help with? Is any other information needed?

       
      • David Nečas

        David Nečas - 2021-08-01

        It is always helpful when I have have more different files. Meaning measured in different modes, with different choices what is saved, …, whatever options exist for Keyence. In other words with [possibly] different structure/content.

        I can write an initial VK6 import implementation using the single file I have. But I have no idea about the variability of the file format. So – in the extreme case – the import module might be able to read just this single file (unlikely to happen here, but you get the idea).

        It would definitely help if you could test the import on a wide set of VK6 files. Of course that can be done only after I actually implement it…

         
        • serafin malyszew

          I will see if the optical microscope will be available for use today and see what other options there are to choose from.

           
  • David Nečas

    David Nečas - 2021-08-02

    I added support for the Keyence VK6 file format, please test (tomorrow's or later development snapshot).

    The import module currently reads the embedded VK4 file and some new metadata. I know how to read the new HDR data too, but I am not sure about the utility of that…

    There is also some kind of error image among the new data. This one could be useful for creating a mask over invalid pixels if this is indeed what it represents. It is just filled with zeros in the file I have – presumably all pixels are good there?

     
  • David Nečas

    David Nečas - 2021-08-03

    I also added import of the VK6 HDR images. The import module replaces the VK4 Peak images with them since this is what they seem to represent. And speculatively it now also reads the Error image, but I have no real example where the Error image contains any information.

     
    • serafin malyszew

      Hello, is there a way to access the arithmetic functions through the pygwy console? I have a short script that opens .vk6 files in a directory and saves them as a different file format. Before the final saving function is initiated however, I would like to apply the "0.2126 * d1 + 0.7152 * d2 + 0.0722 * d2" grayscale operation on the image, with d1 being the height map and d2 being one of the peak images.

      This is what I have currently:

      import gwy, os
      
      root = (r'C:\Users\sm\Desktop\vk')
      gwy_app_set_current_directory(root)
      
      for filename in os.listdir(root):
          if filename.endswith('.vk6'):
              container = gwy.gwy_app_file_load(filename)
              d1 = gwy.gwy_app_data_browser_find_data_by_title(container, 'Height 0')
              d2 = gwy.gwy_app_data_browser_find_data_by_title(container, 'Peak Red')
      
              new_filename = filename.rsplit('.', 1)[0] + '.jpeg'
              gwy.gwy_file_save(container, new_filename, gwy.RUN_NONINTERACTIVE)
      

      I tried to categorize height as d1 and peak red as d2. I am not sure if this can be done in this manner, though. It saves all the .vk6 files as .jpeg, but I am unsure about how to proceed with the arithmetic function as I tried a few different things and they all seemed to crash the console.

      Thank you for your help.

       
  • David Nečas

    David Nečas - 2021-08-18

    No, there is no need. Arithmetic is a C implementation of what you can do in Python much more easily using numpy. Create numpy arrays from the data fields

    a1 = numpy.array(datafield.get_data())
    a2 = numpy.array(anotherdatafield.get_data())
    a3 = numpy.array(yetanotherdatafield.get_data())
    

    and then you can just use any mathematical expressions with the arrays.

     
    • serafin malyszew

      I altered the script and now have this configuration:

      import gwy, numpy, os
      
      root = (r'C:\Users\My HP\Desktop\vk')
      os.chdir(root)
      
      for filename in os.listdir(root):
          if filename.endswith('.vk6'):
              container = gwy.gwy_app_file_load(filename)
              d1 = container['/1/data']
              d2 = container['/2/data']
              a1 = numpy.array(d1.get_data())
              a2 = numpy.array(d2.get_data())
              (0.2126 * a1) + (0.7152 * a2) + (0.0722 * a2)
              new_filename = filename.rsplit('.', 1)[0] + '.jpeg'
              gwy.gwy_app_file_write(container, os.path.join(new_filename))
      

      Running the above script yields the following error:

      "Saving of 'filename.jpeg' failed: file contains no exportable channel. Full file path: 'filename.jpeg' Saved using: jpegcairo."

      I tried changing os.chdir(root) to gwy_app_set_current_directory(root) and gwy.gwy_app_file_write() to gwy.gwy_file_save(), though it still gave the same error expect in the pygwy console itself. If I use gwy.gwy_app_file_save() with no arguments, the program crashes entirely. Other than that, the console seems to be running the script fine, but I am unsure if the script actually carries out the arithmetic operation. Should I assign the mathematical expression to "a3" and then call "a3.data_changed()"? Would something like this be necessary for changes to take effect?

      Thank you.

       
      • serafin malyszew

        Never mind, I made more alterations and have it working successfully on Windows 7. I was having issues with it on Windows 10 as the entire program kept crashing when I ran the script. I will update if there are any other issues, but so far everything seems to be working fine.

        David, thank you very much for all your help with the coding and for implementing .vk6 support!

         
  • Lyle Gordon

    Lyle Gordon - 2021-08-25

    I was really glad to find this thread. I was looking to import some vk6 data. Downloaded the latest nightly and it works perfectly. Thanks for a great program.

     
  • Lucas Schlenger

    Lucas Schlenger - 2024-04-08

    Hi together,

    As a small follow up to ensure the code does not crash on Win 11.:

    I had to include the lines: "gwy.gwy_app_data_browser_set_gui_enabled(False)" to not open a new window for each file I am looping over, and "gwy.gwy_app_data_browser_remove(container) " to release the memory.

    import gwy, numpy, os
    import gwyutils
    import matplotlib.pyplot as plt
    import pandas as pd
    
    root = (r'C:\Users\schlenge\Desktop\Line6')
    os.chdir(root)
    gwy.gwy_app_data_browser_set_gui_enabled(False)
    
    for filename in os.listdir(root):
        if filename.endswith('.vk6'):
    
        container = gwy.gwy_app_file_load(filename)
    
        # create data fields
        d1 = container['/1/data']
        d2 = container['/2/data']
        d3 = container['/3/data']
        d4 = container['/4/data']
    
        gwy.gwy_app_data_browser_remove(container) 
    
        # convert to np.array
        a1 = numpy.array(d1.get_data())
        a2 = numpy.array(d2.get_data())
        a3 = numpy.array(d3.get_data())
        a4 = numpy.array(d4.get_data())
    

    BTW: Amazing work David, much appreciated!

     
  • Vaishnavi Subramanian

    Hi, I m having similar issue in saving the file, i m getting below error, please advise, i m using window 11 , gwyddion 32 bit and python 2.7
    glib.GError: File contains no exportable channel.

     
  • Vaishnavi Subramanian

    Hi, I m having similar issue in saving the file, i m getting below error, please advise, i m using window 11 , gwyddion 32 bit and python 2.7
    glib.GError: File contains no exportable channel.

     
  • Vaishnavi Subramanian

    this is the code i m using, it keeps failing with glib.GError: File contains no exportable channel

    import gwy, os
    root = (r'C:\Users\xyz\Downloads\PyGwy-repo-main\vk6')
    os.chdir(root)
    gwy.gwy_app_data_browser_set_gui_enabled(False)
    for filename in os.listdir(root):
        if filename.endswith('.vk4'):
            container = gwy.gwy_app_file_load(filename)
            d1 = container['/1/data']
            d2 = container['/2/data']
    
            new_filename = filename.rsplit('.', 1)[0] + '.jpeg'
            print(new_filename)
    
        elif filename.endswith('.vk6'):
            container = gwy.gwy_app_file_load(filename)
            d1 = container['/1/data']
            d2 = container['/2/data']
    
            new_filename = filename.rsplit('.', 1)[0] + '.jpeg'
            print(new_filename)
            gwy.gwy_file_save(container, new_filename, gwy.RUN_NONINTERACTIVE)
            print("File Saved Successfully!")
    
     

    Last edit: Vaishnavi Subramanian 2025-02-07

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.