5

I'm trying to implement frequency spectrum image watermarking, using the Fast Fourier Transform and everything is working perfectly, except the fact that I can't save the resulting watermarked image without running into trouble. Since the application is meant to be user-friendly, no hacks regarding photo viewing are acceptable. The user has to be able to download the resulting file and view it as is, without any further modifications.

The code basically goes like this:

import cv, imageio

image = cv2.imread(imagePath, cv2.IMREAD_UNCHANGED)
watermark = cv2.imread(wmPath, cv2.IMREAD_UNCHANGED)

# result is float64, due to the transition from the frequency spectrum to spatial
result = embed_watermark(image, watermark)
imageio.imwrite('result.tiff', result)
result2 = imageio.imread('result.tiff') # Still float64, thanks to tiff format
detection = detect_watermark(result, image)

So, the code is working as wanted, it prevents data loss, thanks to the tiff container, which allows for floating-point pixel values. However, the saved file ('result.tiff') can't be opened with any photo viewer included in MS Windows. If I use any other of the usual containers (jpeg, png, bmp), I am able to visualise the resulting image, but end up losing the watermark information.

I've tried solutions discussed here and here and read the documentation, but I don't seem to wrap my head around this. I have also tried opening the image using FIJI (following Ander Biguri's suggestion, but I get this error: "ImageJ can only open 8 and 16 bit/channel images (64)"

How could I possibly save the file without losing the watermark data, nor the ability to open the resulting file for visualisation?

Bogdan Kandra
  • 150
  • 1
  • 14
  • So, I've tried your suggestion and even FIJI gives me an error; I am going to update the question with the details – Bogdan Kandra Oct 25 '19 at 14:04
  • There is no other solution than: find whatever software that can visualize tiff `float64` data. I have done it with imajeJ, it was just a suggestion. Fidn another one if it does not work, or save it in a format that MS accepts – Ander Biguri Oct 25 '19 at 14:08
  • 2
    There are not many image display tools that work with floating-point data. It is not a problem to save it, but you need a tool that will display it. I would write a Python program to display your image if I were you. – Cris Luengo Oct 29 '19 at 13:18
  • The application I am working on is intended to be used by regular users. They select operation(s) to be applied, select the input images and submit the selections. The server would send the processed images to the client for display and the user has the option of downloading the results. So any hack for displaying the watermarked image is not acceptable – Bogdan Kandra Oct 29 '19 at 16:17
  • If the tiff version works, could you just then re-export the watermarked tiff version as a jpeg/other format? – Matt Eding Oct 31 '19 at 23:39
  • 1
    Is it absolute that you need the image in TIFF format? – Kevin Ng Nov 01 '19 at 16:34
  • 1
    You say you lose the watermark information when saving as one of the other formats. So is the issue at play here that the watermark information is too insignificant to be preserved with just 8 bits per channel? Or is it that the detection can't handle non-float data? The comments in your code above make it sound like the latter, but that would be easily solved. I suspect it's the former, in which case you should clearly state that in your question. – blubberdiblub Nov 01 '19 at 16:38
  • @blubberdiblub AFAIK, the issue is that modifying the frequencies in the frequency spectrum yields float numbers when returning to the spatial spectrum (by taking the magnitudes of the complex numbers returned by the Inverse Fourier Transform). So saving in any other format (that I know of) truncates the values to integers, resulting in loss of information. The detection CAN handle non float data, but that is not the issue. Also, as I have mentioned in the question, if saving in TIFF format, the secret message can be successfully stored and detected, but the resulting image undisplayable. – Bogdan Kandra Nov 04 '19 at 13:55
  • I'm basically looking for a way to modify the frequencies, return to the visual domain and save the result in a way that is displayable for the user AND which keeps the secret information for later detection – Bogdan Kandra Nov 04 '19 at 13:56
  • 1
    @KevinNg I'm open for any other suggestions, I actually resorted to TIFF because it's the only format which can represent floating point data (that I know of) – Bogdan Kandra Nov 04 '19 at 13:58
  • If the original image is in 8 bits (?) and the watermark is so insignificant that it requires more than 16 bits to be detectable, wouldn't that render the watermarking useless? Just strip off LSBs and you get an unmarked image again... – Jeronimo Nov 04 '19 at 14:50
  • @BogdanKandra it still doesn't sound like the image format by itself is the issue here. Please consider "undisplayable" a completely separate issue from the loss of watermarking information. It doesn't seem unusual to me that an image consisting of float values saved in a format that supports float values, but which uses a less popular on-disk format in this case, cannot be displayed by most run-of-the-mill image viewers. Also, integer vs. float shouldn't be the problem here. Rather, the number of significant bits might. 8-bits-per-gun (int) vs. 24-bits-per-gun (float) is a big difference. – blubberdiblub Nov 04 '19 at 16:28

0 Answers0