GCR option giving error
shankhya opened this issue · comments
h.make() is working, but as soon as I am adding the GCR % as an option the following error is occuring:
h.make(percentage=50)
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\shank\Documents\Documents\Halftone\halftone.py", line 63, in make
cmyk = self.gcr(im, percentage)
File "C:\Users\shank\Documents\Documents\Halftone\halftone.py", line 88, in gcr
cmyk[i][x, y] = cmyk[i][x, y] - gray
TypeError: color must be int or tuple
Can you please help me solve this issue.
Also is there any way I could view and save individual C, M, Y, K channels instead of the composite file.
Thanks.
Sorry, yes I see now - I was confused by mention of a GCR option :)
I've fixed the bug - I'm guessing it might be something that used to work with python 2 but doesn't with 3.
I've added a save_channels=True
option that you can pass in, which will save out the individual channels. Currently they're all black-and-white because that's just how they come - would it be more useful if the cyan channel was cyan-and-white, etc?
Thanks a lot. The "percentage"option is working now. Also the channels are saved into individual files.
Would be nice if along with the grayscale channels, the same may be colored as you mentioned. But keep the option to save the individual channels in grayscale as well.
Also now another problem I ran into, is while using the antialiasing option. Could you take a look.
Thanks a lot again.
I've fixed that in the latest code.
I don't know how to colour the individual channels' files. I've tried a bunch of things but I don't use Pillow much these days so I'm unsure. I'll maybe post on StackOverflow and see if I can get some ideas.
I've changed the new save_channels
option so you can pass in one of:
save_channels="grayscale"
save_channels="color"
Can you have a go when you get a chance and let me know if it works for you?
Yes it has worked. Both the save_channels option as well as antialias option are working. Thanks. Also it may be too much to ask for, but is there any chance this code could save the individual channels in 1-bit files while preserving the dot shapes? If its not possible no problem. Thanks a lot for helping and getting the code to work at my end.
I'm not really sure what you mean by 1-bit files?
Understood. Is that not the same as turning off antialiasing?
Tried. But as you can see, although the effect with antialias OFF (RIGHT) is much better than when it is ON (LEFT).
But still within the individual dot itself, the pixel intensity is not equal and even the non-image (white) areas have some pixel intensity (although very less). But if the dots would all have the same pixel intensity then it would simulate a 1-bit depth image. The problem is when I open this RIGHT image in photoshop and convert it into bitmap, the following result is obtained. LEFT Image= single channel before bitmapped. RIGHT Image=After bitmapped.
Essentially photoshop is switching off pixels that are slightly lower intensity than the rest. This problem would be solved all pixels within a dot would have equal intensity.
Ah yes. This is, I think, because the images are JPGs, and the compression while saving to a JPG is creating the "noise" from what would be a black-and-white image. As far as I know JPGs can't be 1-bit.
At the moment it writes out the same format image as the input. Although I've just noticed that if you try to feed it a PNG, then it throws an error when trying to write the four separate channel files because PNGs can't be CMYK (which I can fix).
Maybe there should be an option for output format, either None
(same as the input),
"jpg"or
"png"`?
Another thought - the four separate channels, if output as PNGs, could maybe (optionally) have a transparent background instead of white. I don't know how to do this, but does that sound useful?
As long as the channel files are output as CMYK, png format is ok. Also does TIFF support this? Normally, RIP engines in CTPs (Computer to Plate) outputs their files as 1-bit (depth) TIFFs. That's why I thought of this. But if it is possible to get the dots with same intensity with the white areas with no intensity (transparent may work) the purpose may be solved.
Have a go with the latest version. Note that I've changed the save_channels
argument so it's now a boolean. I've also added these arguments:
save_channels_format
("default", "jpeg" or "png")save_channels_style
("color" or "grayscale")output_quality
(0
to100
, default is75
, only for JPEG output.
Let me know what you think.
The code worked exactly as I wanted it to. When I open the jpg in Photoshop, very few pixels in the background are ON. But this will work. Thanks a lot for helping.
Also I had a question. Since we normally use an ICC profile for RGB to CMYK image conversion in photoshop, what is the profile that is used in your code for the same? And can that profile be user defined?
Great, glad to hear. I've just added an output_format
option so you can output the main combined image as PNG or JPEG, no matter what the input file.
As far as I can tell there's no specific ICC profile used by Pillow for conversion. I don't really understand colour profiles I'm afraid. You may have noticed that the colours are different for the output JPEGs (which are CMYK) and PNGs (which are RGB), which I assume is down to not using a colour profile. I've opened a new issue for this #7, but I have no idea how to fix it.