Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does the multisampling work? #11

Open
yaqwsx opened this issue Jan 12, 2020 · 20 comments
Open

Does the multisampling work? #11

yaqwsx opened this issue Jan 12, 2020 · 20 comments
Assignees

Comments

@yaqwsx
Copy link

yaqwsx commented Jan 12, 2020

I use the library version from the master branch. I have a following snippet to create a CBDDLP file from a list of images:

mars = Photon()
mars.layer_levels = mars.anti_aliasing_level = aaLevel
mars.exposure_time = exposure
mars.exposure_time_bottom = bottomExposure
mars.layer_height = layerHeight
mars.bottom_layers = bottomCount

files = list(glob.glob(globPattern))
for i, file in enumerate(files):
    report(i + 1, len(files))
    layerImage = Image.open(file).convert("L")
    mars.append_layer(
        [imageToRle(layerImage.point(lambda x: threshold(i / aaLevel, x)))
            for i in range(aaLevel)])
mars.write(outfilename)

I supplied a single layer with a gradient black/white and used level 8 of anti-aliasing I was expecting to see 8 images - with more a more exposed area of the display. However, that was not the case, neither saw I a gradient. Does the AA feature of this library works?

The file I generated: http://files.honzamrazek.cz/grad2.cbddlp

Could you try the file on your printer? How is the AA feature supposed to work?

@fookatchu
Copy link
Owner

If I understand correctly you want to create a new cbddlp file with anti-aliasing from a single image? This does not work. The library expects that you supply an image / sublayer for each level of anti-aliasing that you want. For example anti-aliasing with level two expects two images / two sublayers. Those will then sequentially cured by the printer but at the same layer height.
If I am correct, I would suggest that you generate a AA file with chitubox und export the images with pyphotonfile and have a look how they are arranged. If I am mistaken, please let me know.

@yaqwsx
Copy link
Author

yaqwsx commented Jan 19, 2020

This is what I do: I take a grayscale image and generate n images by thresholding the grayscale image:

[imageToRle(layerImage.point(lambda x: threshold(i / aaLevel, x)))
            for i in range(aaLevel)])

This is not the correct approach?

I expect these images to be subsequently shown on the same height. But it is not what I observe (only the first one is shown for the whole time).

@X3msnake
Copy link

X3msnake commented Jan 20, 2020 via email

@yaqwsx
Copy link
Author

yaqwsx commented Jan 20, 2020

I am aware of the bug (as I reported it when I was troubleshooting this issue). Even after the bug was fixed, the problem is preserved. Or does the sliced file produce expected results on your printers?

@X3msnake
Copy link

X3msnake commented Jan 20, 2020 via email

@X3msnake
Copy link

X3msnake commented Jan 20, 2020 via email

@yaqwsx
Copy link
Author

yaqwsx commented Jan 20, 2020

The problem with reassembling the file is that I get only a slightly different sublayer from the slicer, which I am not able to detect by eye when run on a printer (and I probably have no other method to detect if the multisampling still works).

The whole code is in the initial issue message, the only missing functions are:

def imageToRle(image):
    return imgarr_to_rle(np.array(image))

def threshold(level, pixel):
    # Turn on the dim pixel at the last
    if pixel >= (1 - level) * 255:
        return 255
    return 0

I have verified that the thresholding works as expecting (by saving each sublayer to an image file).

@X3msnake
Copy link

X3msnake commented Jan 20, 2020 via email

@yaqwsx
Copy link
Author

yaqwsx commented Jan 23, 2020

I tried your suggestion - to get a working file from the slicer and just to rewrite the images. I also tried to generate an AA file from scratch; below is my code:

def testPattern(i, aaLevel):
    x = np.linspace(0, 255, 2560)
    image = np.tile(x, (1440, 1)).T
    image[image >= (1 - (i + 1) / 8) * 255] = 255
    image[image != 255] = 0
    return image

def testAA():
    mars = Photon("AAExample.cbddlp")
    print("layer_levels: {}".format(mars.layer_levels))
    print("anti_aliasing_level: {}".format(mars.anti_aliasing_level))
    for i in range(len(mars.layers)):
        print("Layer")
        for sublayerId, sublayer in enumerate(mars.layers[i].sublayers):
            image = testPattern(sublayerId, 8)
            sublayer._data = imgarr_to_rle(image)
    mars.write("test.cbddlp")

def genAA():
    mars = Photon()
    mars.layer_levels = mars.anti_aliasing_level = 8
    mars.exposure_time = float(10)
    mars.exposure_time_bottom = float(10)
    mars.layer_height = float(0.05)
    mars.bottom_layers = int(10)
    for i in range(10):
        print("Layer")
        mars.append_layer(
            [imgarr_to_rle(testPattern(j, 8)) for j in range(8)])
    mars.write("gen.cbddlp")

The produced files are in the attachment.
slicedFiles.zip

The rewritten file worked as expected; the generated one did not. What am I doing wrong?

@X3msnake
Copy link

X3msnake commented Jan 24, 2020 via email

@yaqwsx
Copy link
Author

yaqwsx commented Jan 24, 2020

The code above generates the image, so there cannot be a difference. I think the problem is with the setup of the empty file; If I change

mars = Photon()

to

mars = Photon("AAExample.cbddlp")
mars.delete_layers()

and append layers, I get the correct result.

Also, the next thing I noted is that mars.layer_levels = mars.anti_aliasing_level = 8 has no effect - the number of sublayers stays the same in the output file. This would explain why I wasn't able to get antialiasing working with the original code - the antialiasing level was still one.

@fookatchu
Copy link
Owner

The 'empty file' falls back to a .photon-file which I generated for the v1 format, as I was not able to generate a new file from scratch due to limited knowledge of the fileformat. I think this is most likely the source of the problem. I will make a new file for the v2 format or generate a new file from scratch, which would be better for building packages. In the meantime, you can use your own file and just delete all layers before adding new ones.

@yaqwsx
Copy link
Author

yaqwsx commented Jan 24, 2020

Thank you for the response. I understand the problem with the initial file. However, I was wondering, do you have any idea why changing the anti-aliasing level does not work? I would like to be able to change it. Having several pre-generated files with AA level could work, but I am aiming to experiment with AA levels which ChiTuBox refuses to produce (I guess it is due to the limitation of the drop-down form and I would like to test if the printer can handle non-standard AA level).

Could you point me to materials about the file format you used during the development?

@fookatchu
Copy link
Owner

Currently I do not know why this doesn't work, but I have to have a look at your code and get into my write-method again. I will try to produce a working example in the next days on how to generate a new AA-file from scratch. Theoretically it should work but I mostly tested the library with pregenerated files, and not with 'from scratch' generation.
For the fileformat reference I used mostly CBDDLPinfo as a reference.

@X3msnake
Copy link

X3msnake commented Jan 24, 2020 via email

@X3msnake
Copy link

https://github.com/Photonsters/anycubic-photon-docs/blob/dev/Temp-resources/ExpTestCreatorAA.zip

Maybe this file will help. it was made by @Cex123 same as the cbddlpinfo by my request when i was trying to investigate AA on photon.

the code there might shed some light

@EelcoHoogendoorn
Copy link

Excuse a potential thread hyjack; but I am also looking into writing valid photon AA files, and I want to check part of my understanding.

In the implementation of tresholding as discussed here, each sublayer has the same exposure time; so 8 AA levels means 8 distict levels of exposure.

Is it also possible to have 8 sublayers, each with its own exposure time? If we had 8 exposures, the i-th of which had base*2**i exposure time, and each subimage would simply be the 8-bit grayscale image with a bitmask applied, we should be able to realize the full 256 bit depth of exposure times. Or use just 4 images to get 16 different values, etc.

After I wrote this, I noticed the comment '# currently ignored by firmware?' wrt per sublayer exposure time; so I suppose this is not going to fly...

@X3msnake
Copy link

X3msnake commented Feb 3, 2020 via email

@fookatchu fookatchu self-assigned this Feb 16, 2020
@yaqwsx
Copy link
Author

yaqwsx commented Apr 18, 2020

Hi, is there any progress regarding this issue?

@fookatchu
Copy link
Owner

Not yet, I have been busy with other projects. If anyone else wants to give it a shot, I would be grateful. I currently don't use the Photon anymore, so any help is appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants