Embed QrCode in fpdf in CMYK - png

I used a fpdf class extension (http://www.fpdf.org/en/script/script44.php) to handle CMYK in the PDF, and all is fine: I can print my texts with 100% K in CMYK.
Then, I needed to generate a QrCode to be embedded into a PDF using fpdf.
I did it using PHPQrCode (http://phpqrcode.sourceforge.net/), and it works fine for my purposes.
All is fine on screen, but I need to send that PDF to a print shop to be professionally printed in CMYK.
I directed a book publishing company for 10 years so I am well aware of the "issues" with color handling, especially in this specific case in which the black RGB (0,0,0) absolutely DOES NOT match with the CMYK black (0,0,0,100). It will be converted to a very dark, but not fully black, 4-color-layers, and when printed, it will look both bad and usually nasty due to problems of "registro e retinatura" (those are technical printing terms of which I do not know the translation)
Now, my QrCode is in PNG, which is RGB, fine, I get it. But since the QrCode is actually just one bit, 0/1, white/black, isn't there a different file format that lets me specify the "black" as "black" in CMYK - that is 0,0,0,100?
From what I read, not even JPG is CMYK - it's something in between (JPG uses a color model named YCbCr. It is neither RGB nor CMYK.). It sounds like a video signal standard to me :(
If I cannot find a solution, I will leave the PNG with the RGB black: it will look bad, but hopefully using the highest error correction in the QrCode, it will still be readable :(

Related

Load PNG RGBA channels like interleaved JPG RGB channels

Can a PNG file's data be loaded in a certain order, say beginning with one RGBA channel, then the rest?
Perhaps similar to how JPG files can, sometimes using custom codecs, store their data as "scans" or "slices", that are loaded progressively, sequentially or interleaved, at first displaying black and white, followed by red, green, and finally blue.
It seems very unlikely, but can PNG files have a way of behaving like this?
References:
https://cloudinary.com/blog/progressive_jpegs_and_green_martians
Besides standard/progressive, the 3rd kind of JPEG compression: load by channel?
https://graphicdesign.stackexchange.com/a/55570/97317
PNG's equivalent to JPEG's progressive display is interlacing. Rather than interlacing lines, it interlaces pixels using a pattern the PNG standard calls ADAM7.

Making the "Region of Interest" (ROI) transparent in MATLAB

I've already made a function to cut out the image, and the part I cut out has a black background. I'm trying to make the black part transparent, then I can generate an image sequence that I can create a video with. I've tried converting the image to a double and then replacing the 0 values with NaN:
J = imread('imgExample.jpg');
J2 = im2double(J);
J2(J2 == 0) = NaN;
imwrite(J2, 'newImg.jpg');
but when I convert it into a video, it doesn't seem to stay. Is there any way to get the black part of the image to be transparent?
From clarifications in comments, you are trying to create a video format that supports alpha transparency using matlab.
In general this seems impossible using matlab alone (at least in matlab 2013 which is the version I use). If you'd like to check if the newest matlab supports videos with alpha transparency, type doc videowriter and have a look at the available formats. If you see anything with transparency options there, take it from there. But the most I see on mine is 24bit RGB videos (i.e. three channels, no transparency).
So matlab does not have the ability to produce native .avi video with alpha transparency.
However, note that this is a very rare video format anyway, and even if you did manage to produce such a video, you would still have to find a suitable viewer which supports playing videos with transparency!
It's therefore important for you to tell us your particular use-case because it may be you're actually trying to do something much simpler (which may or may not be solvable via matlab) (i.e. a case of the XY Problem
E.g. you may be trying to create a video with transparency for the web instead, like here https://developers.google.com/web/updates/2013/07/Alpha-transparency-in-Chrome-video
If this is the case, then I would recommend you attempting the method outlined there; you can create individual .png "frames" with transparency in matlab using the imwrite function. have a look at its documentation, particularly the section about png images and the 'Alpha' property. But beyond that, you'd need an external tool to combine them into a .webm file, since matlab doesn't seem to have a tool like that (at least none that I can see at a glance; there might be a 3rd-party toolkit if you look on the web).
Hope this helps.

PIL: converting an image with mode "I" to "RGB" results in a fully white image

The image at the end of this question is a PNG with mode I, which stands for Indexed, as far as I can tell.
I'm trying to create a thumbnail out of it, and save it as JPG with PIL.
However, is I leave the mode alone, PIL won't let me resize it with error unable to generate thumbnail: cannot write mode I as JPEG.
If I convert it to RGB, the result will be a fully white image.
Is there a way to fix this?
https://www.dropbox.com/s/2d1edk2iu4ixk25/NGC281.png
The input image is a 16-bit grayscale PNG, and it appears PIL has a problem with this. Manually converting it to an 8-bit image before further processing makes it work again.
The problem may originate inside PIL itself. The PyPNG homepage asserts
..PIL only has internal representations (PIL mode) for 1-bit and 8-bit channel values. This makes me wonder if PIL can read PNG files with bit depth 2 or 4 (greyscale or palette), and also bit depth 16 (which PNG supports for greyscale and RGB images).
Then again, that page is from 2009. It could be worth tracking down where PIL is maintained from, and report this as a bug (? Or possibly a feature request?).

Transparency with JPEGs

JPEGs are smaller in size than PNGs. So, I thought that if I can make a specific region in a JPEG-file transparent, with some code, maybe I can save some bytes.
So does anyone know how to achieve this with for example PHP or JavaScript?
No. You can't do this. JPGs do not support alpha channels and have no capacity to designate certain colors as transparent either (GIF-style).
There's several issues with this, all of them have to do with that JPEG is a lossy compression format. The JPEG format is optimized for natural images and sharp edges will get blurred. If you intend that a specific pixel should have the value #d67fff there's no guarantee that after color conversion, FDCT, quantization, IDCT and color conversion, the pixel still will have that value. There's also a strong possibility that that pixel value will occur in areas that you don't want.
No. JPEG does not support transparency and is not likely to do so any time
soon. http://www.faqs.org/faqs/jpeg-faq/part1/section-12.html
You cannot do that, the client renders the image and doesn't know that you want it to treat that color as transparent (plus various compression methods on jpeg wouldn't work well with transparencies anyway).
I believe you can go with an 8-bit custom-pallet png, should save you a lot of space. Otherwise 24-bit PNG is your only high color option.
You can convert your image to SVG containing a color information as JPEG and an alpha channel as grayscale mask. Here is a tool I wrote to do it https://github.com/igrmk/transpeg

MATLAB: print pdf in black/white

Matlab prints figures in either black/white or color. A black/white print of a figure is NOT the same as a color print tweaked to black/white: every color including the light ones is translated as black. (Light colors that look good on screen or a color printer look horrible on a black/white printer)
I would like to print a PDF file of a figure. My problem is that there doesn't seem to be a PDF driver for MATLAB that outputs black/white rather than color.
See the print command: -dpdf is the PDF driver but it is color.
Is there any way I can do this?
(edit: http://www.mathworks.com/access/helpdesk/help/techdoc/creating_plots/f3-84337.html#f3-99776 shows the interactive way of doing this, but I need a programmatic method, otherwise it will get tedious rather quickly.)
You can fully automate the print process: http://UndocumentedMatlab.com/blog/customizing-print-setup/
You could convert it to an EPS (-deps or -deps2) and then use eps2pdf (which uses GhostScript) to convert that into a PDF. I generally convert all my figures to this way.