I have watermarked a bunch of images image with PIL (PILLOW in fact).
I have the original watermark and I know exactly how it has been resized and pasted on the image (0.75 opacity). The watermark is essentially black, white and red.
I want to restore images as close as possible as they were originally.
Is there any chance I could do that automatically?
What about quality? Is it worth it? Do you have examples of the result of such a process?
If so, how would I manage to do this?
Here is the code I used to watermark the image:
logo = Image.open(path)
red, green, blue, alpha = logo.split()
alpha = ImageEnhance.Brightness(alpha).enhance(0.75)
logo.putalpha(alpha)
img = Image.open('...')
img = Image.composite(logo, img, logo)
I've made a mask with of my logo and use GIMP's G'MIC plugin : http://blog.patdavid.net/2014/02/getting-around-in-gimp-gmic-inpainting.html
Here is as far as I can get, which is not really good enough:
This has been made with inpainting technic, but I am sure I could somehow exploit the fact that my watermark is somewhat transparent.
I've also tried to unblend the picture, given the watermark and watermarked pictures as input.
Unforunately, the watermarked picture being compressed in jpeg, I couldn't get any better than this :
Related
So I need to post an RGB picture (with transparent background) onto background image, but when I am trying to post it with image.paste() I get transparent background through which I don't see the background I want. What should I do?
Thanks!
Code (its just that):
skin = Image.open("./temp2.png")
skin = skin.resize((148, 355))
stats.paste(skin,(42,232))
stats.save("temp.png")
Images:
Image I want to paste
The background I want to paste it on
Wanted Result
Actual Result (gray is transparent)
You can use alpha composite in PIL to paste an image and keep the alpha channels for transparency.
stats = Image.open("stats.png")
skin = Image.open("skin.png")
skin = skin.resize((148, 355))
stats.alpha_composite(skin,(42,232))
stats.save("temp.png")
Resulting image:
I am trying to crop only liver from this picture. I have tried everything but cannot find any useful information about it. I am using Python/Rstudio. Also after removing the unnecessary part, I am willing to get pixels/intensity of the new image. Any help would be appreciated. Please check one of the image This is somehow what I want to crop
UPDATE:
I am trying to crop the main image based on edges I got from the canny edge detector. Is there any way to crop the main image based on edges? Please check the images.
Liver Image
Canny Edge Detection
Well, if your images are static, same size, and taken from the same angle, then below simple script should suffice your needs:
import cv2
img = cv2.imread("cMyp9.png")
mask = np.where(img==255)
img2 = cv2.imread("your_next_image.png")
img2 [mask] = 255
now your img2 is a cropped version
I'm trying to resize images while keeping aspect ratio. I use PIL's thumbnail method for this. I use Image.ANTIALIAS filter.
You can check my code here:
image = Image.open(design.design.path)
format = image.format
image = ImageOps.mirror(image)
new_size = (241, 241)
image.thumbnail(new_size, Image.ANTIALIAS)
image.save(response, format)
This code works perfectly however quality is lost after thumbnail. I can see it by zooming in on the saved image. I can see pixels at the corners of the image while I don't on the original image. This is seen even better when I print out resized image.
You can check out sample images here: http://imgur.com/a/ifZoU
Please tell me if you need anything else
Image.save has options for you:
img.save(fpath, 'image/png', quality=100, optimize=True)
If you are making thumbnails of a pixel-based image, of course you will loose quality. Re-sizing this kind of image (as opposed to vector images) simply throw information away - there is no way to recover it.
IF you need to view the image in full size, you have to preserve the original image, and keep the scaled-down version to be shown only where it is needed - use the original for everything else.
https://en.wikipedia.org/wiki/Raster_graphics
I have some traffic camera images, and I want to extract only the pixels on the road. I have used remote sensing software before where one could specify an operation like
img1 * img2 = img3
where img1 is the original image and img2 is a straight black-and-white mask. Essentially, the white parts of the image would evaluate to
img1 * 1 = img3
and the black parts would evaluate to
img1 * 0 = img3
And so one could take a slice of the image and let all of the non-important areas go to black.
Is there a way to do this using PIL? I can't find anything similar to image algebra like I'm used to seeing. I have experimented with the blend function but that just fades them together. I've read up a bit on numpy and it seems like it might be capable of it but I'd like to know for sure that there is no straightforward way of doing it in PIL before I go diving in.
Thank you.
The Image.composite method can do what you want. The first image should be a constant value representing the masked-off areas, and the second should be the original image - the third is the mask.
You can use the PIL library to mask the images. Add in the alpha parameter to img2, As you can't just paste this image over img1. Otherwise, you won't see what is underneath, you need to add an alpha value.
img2.putalpha(128) #if you put 0 it will be completly transparent, keep image opaque
Then you can mask both the images
img1.paste(im=img2, box=(0, 0), mask=img2)
I'm fairly new to PIL and having issue with some image processing. I'm just trying to resize an image to a different resolution using PIL:
resized_hd = image.resize((hd_width, hd_height), Image.ANTIALIAS)
However, the resized picture does not look as good/bright as the original one.
Original (5184*3456) -> http://d31d9cjolqcwln.cloudfront.net/San+Francisco/sutro+baths.jpg
Resized (2048*1366) -> http://d31d9cjolqcwln.cloudfront.net/San+Francisco/HD-sutro+baths.jpg
Any guess ?
I think it's because one of the two images (the original one) has an embedded color profile, which the other one (the resized one) doesn't have. I discovered this by trying to open the original image in gimp. The color profile will cause advanced viewers to make corrections, in theory to fix differences like the ones between paper and screen. When I view the two images in a simple viewer that doesn't know about color profiles, they are really the same brightness. It looks like the PIL library ignores the color profile and doesn't carry it onto the resized image.
I can't help you more precisely than that, though, as I don't know much about color profiles. There might be tools to copy the profile over.
Kuddo to Armin for his suggestion.
Pil allow you to attach an ICC profile to a resized image using the following code:
icc_profile = im1.info.get('icc_profile')
im6 = im1.resize((hd_width, hd_height), Image.ANTIALIAS)
## this one will preserve the colours
im6.save("colorok-"+image,icc_profile=icc_profile)
## this one don't
im6.save("nop-"+image)