Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
Looking for some kind of simple tool or process for Windows that will let me convert one or more standard PNGs to premultiplied alpha.
Command line tools are ideal; I have easy access to PIL (Python Imaging Library) and Imagemagick, but will install another tool if it makes life easier.
Thanks!
A more complete version of the cssndrx answer, using slicing in numpy to improve speed:
import Image
import numpy
im = Image.open('myimage.png').convert('RGBA')
a = numpy.fromstring(im.tostring(), dtype=numpy.uint8)
alphaLayer = a[3::4] / 255.0
a[::4] *= alphaLayer
a[1::4] *= alphaLayer
a[2::4] *= alphaLayer
im = Image.fromstring("RGBA", im.size, a.tostring())
Et voila !
Using ImageMagick, as requested:
convert in.png -write mpr:image -background black -alpha Remove mpr:image -compose Copy_Opacity -composite out.png
Thanks #mf511 for the update.
I just released a bit of code in Python and in C that does what you are looking for. It's on github: http://github.com/maxme/PNG-Alpha-Premultiplier
The Python version is based on the cssndrx response. C version is based on libpng.
It should be possible to do this through PIL. Here is a rough outline of the steps:
1) Load the image and convert to numpy array
im = Image.open('myimage.png').convert('RGBA')
matrix = numpy.array(im)
2) Modify the matrix in place. The matrix is a list of lists of the pixels within each row. Pixels are represented as [r, g, b, a]. Write your own function to convert each [r, g, b, a] pixel to the [r, g, b] value you desire.
3) Convert the matrix back to an image using
new_im = Image.fromarray(matrix)
Using PIL only:
def premultiplyAlpha(img):
# fake transparent image to blend with
transparent = Image.new("RGBA", img.size, (0, 0, 0, 0))
# blend with transparent image using own alpha
return Image.composite(img, transparent, img)
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have to store a 1MByte word file into a 512x512 pixels image using Matlab and extract it again. The only thing that I know is that we have to remove the invaluable bits of the image (the ones that are all noise) and store our fie there.
Unfortunately I know nothing about both Matlab and Image Processing.
Thanks All.
Given the numbers provided, you can't. 512x512 give 6.2MBit given 24 bits per pixel. So your doc is larger than the image you are hiding it in.
If we ignore the above, then this is what you have to do:
Load the image and convert to uints.
Mask out a number of LSB bits in each pixel.
Load the doc as binary and fill those bits in where you
masked the others out.
Now, from the above to actual code is a bit of work. If you have no experience with matlab it won't be easy. Try reading up on imread() and bit operations in matlab. When you have some code up and running, then post it here for help.
Regards
In matlab you can read images with imread()
(details on: http://de.mathworks.com/help/matlab/ref/imread.html?s_tid=gn_loc_drop )
Image = imread("Filename.jpg")
figure()
imshow(Image)
This code would show you the Image in a Window.
I think what you're looking for is steganography instead of watermarking.
Steganography:
https://en.wikipedia.org/wiki/Steganography
Here is an example of an image with a file inside it:
http://marvinproject.sourceforge.net/en/plugins/steganography.html
Related topic:
Image Steganography
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I work in my project on the problem of writer recognition from handwritten Arabic documents.
to identify the writer, I used a database image,
My problem is how to extract features from these images. I'm new in matlab and I do not have much knowledge in image processing.
please help me, I need to extract the contour from image and then encode it using freeman chain codes.
The following link contains freeman code in matlab but I do not know how to use it.
I welcome your suggestion and thank you in advance
You can use the imcontour function.
For instance, if you load this sample image
Img = imread('test.png');
You can get the contour with the command:
C = imcontour(Img, 1);
Then you can use the freeman function you cite with C as the first input.
Another example could be to use bwperim. This essentially takes a look at all of the distinct binary objects in an image and extracts the perimeter of each object. This only works for objects that are white, and so using #Crazy rat's example, we can thus do:
im = ~im2bw(imread('http://i.stack.imgur.com/p9BZl.png'));
out = ~bwperim(im);
The above will read in the image and convert it into binary / logical. Next, we need to invert the image so that the object / text is white while the background is black. After, call bwperim so that you extract the perimeter of the objects, and then to convert back so that the object text is black, we re-invert.
The output I get is:
The distinct advantage with bwperim over imcontour is that bwperim provides the actual output image whereas imcontour only draws a figure for you. You can certainly extract the image data from the figure, like using the h = gcf; out = h.cdata; idiom, but this will include some of the figure background in the result. I suspect you would like the actual raw image instead, and so I would recommend using bwperim.
How do we use this with the Freeman code you linked?
If you look at the source code, it takes in two inputs:
b, which is a N x 2 matrix of coordinates that determine the boundary of the shape you want to encode
unwrap - An optional parameter
If you want to use the function that you have linked us to, simply extract the row and column coordinates of those pixels that are along the boundary of your image. As such, this is another limitation of imcontour, as you won't be able to determine these locations without the raw contour image itself. Therefore, all you really have to do is:
[y,x] = find(out == 0);
cc = chaincode([y x]);
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
I'm trying to convert a grayscale image to rgb image . I searched the net and found this code:
rgbImage = repmat(grayImage,[1 1 3]);
rgbImage = cat(3,grayImage,grayImage,grayImage);
but what this does is only give the image in gray-scale with 3-D matrix.
I want to have a way that i can convert it into true color image.
It's impossible to directly recover a colour image from the grey scale version of it. As correctly said by #Luis Mendo in the comments, the needed information are not physically stored there.
What you can do is try to come up with a mapping between intensity level and colour, then play around with interpolation. This however will not produce a good result, but just some colour mapping information that may be very far from what you want.
If you have another colour image and you want to fit its colours to your grey scale image, you may want to have a look at: http://blogs.mathworks.com/pick/2012/11/25/converting-images-from-grayscale-to-color/ .
In particular the function that is there cited can be found here: http://www.mathworks.com/matlabcentral/fileexchange/8214-gray-image-to-color-image-conversion#comments.
Bare in mind that this will be slow and will not produce a great result, however I don't think you can do much more.
yes it's impossible to directly convert gray scale image to rgb..but it is possible to add features or show something like an edge detected on gray scale image in rgb by adding it..if you want you can use this..
rgb = zeros([size(I_temp) 3]);
rgb(:,:,1) = im2double(rr);
rgb(:,:,2) = im2double(rg)+.05*double(I_temp) ;
rgb(:,:,3) = im2double(rb);
where rr,rg,rb are an rgb base image..
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I have a very high number of small images (360x192), taken in sequence as screenshots from a DOS 2D computer game. They have decent overlap and i'd like to stitch them together into one big composite. Due to their very nature each subsequent image will fit pixel-perfect over the next or previous one. As such no rotation, stretching or distortion is required OR desired.
There is a lot of software out there to stitch together photo panoramas. But sadly all of them apply some distortion, even when they're explicitly instructed not to do so.
Is there software that will try to do pixel-perfect stitching?
Mathematica 8 features functions to do that:
ImageAlign[img1, img2, "Transformation" -> "Translation"]
FindGeometricTransform[img1, img2, "Transformation" -> "Translation"]
By setting the option "Transformation" to "Translation" you are guaranteed that the result transformation will not have any of the "distortions" you are mentioning.
More examples in the documentation:
http://reference.wolfram.com/mathematica/ref/ImageAlign.html
http://reference.wolfram.com/mathematica/ref/FindGeometricTransform.html
I know one can link Mathematica to perl, but I have not tried it yet.
EDIT: Using the link you sent, I came up with the following. The only problem is that you need to specify in advance the size of the output---NB I tried only the first 10 images.
directory = "~/Downloads/done/";
files = FileNames["*.bmp", directory];
canvas = ImagePad[Import[files[[1]]], {{100, 100}, {500, 100}}, Transparent];
Do[
i = Import[f];
fun = FindGeometricTransform[canvas, i, "Transformation" -> "Translation"];
If[Head#fun === FindGeometricTransform,
Continue[]
];
canvas = ImageCompose[
canvas,
ImagePerspectiveTransformation[i, fun[[2]], DataRange -> Full, PlotRange -> Transpose[{{0, 0}, ImageDimensions[canvas]}], Padding -> Transparent],
{1, 1, -1}],
{f, files[[;; 10]]}]
One of the definitive libraries to do panorama stitching is Panorama Tools. You can either port or call from Perl.
Note that your specification is at odds. Unless you images are 100% rectilinear (i.e., taken 1:1 by an imager the same size as the image) you MUST compensate for the lens distortion. To accurately stitch photos together (pixel by pixel) the image needs compensating distortion.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I know how to do simple things with images at the pixel level like applying grayscale, sepia, etc. I'd like to find some articles on how to apply saturation, hue, brightness, contrast, etc at the pixel level, and I'm having trouble getting anything useful from my google searches.
Since pixels are usually represented as RGB (red, green, blue) values, it's often more useful to convert them to another color space to manipulate them, e.g. HSB (Hue, Saturation, Brightness) - that way you can change those values individually more easily.
If you search for RGB to HSB conversion you should find examples of how to do it (I think I found some useful code on Wikipedia).
Obviously after you've manipulated the pixels (e.g. multiplying the saturations by 0.2) you then have to convert them back to RGB for display.