As such, you simply need to change the last statement of the code before you show the final image. Now, supposing you want to change the location of the logo so that it appears in either the top right, bottom left, or bottom right. Jack(1:rows,1:cols,:) = uint8(alphaResize.*double(logoResize) +. %// Get the size of the resized logo - we need this %// Duplicate the alpha map to make this three channels - This is a colour imageĪlphaResize = repmat(alphaResize, ) %// Make sure you do the same for the alpha mapĪlphaResize = imresize(alpha, 0.1, 'bilinear') LogoResize = imresize(logo, 0.1, 'bilinear') Jack = imread('Kiefer-Sutherland-in-24.jpg') Note that I have saved the images to my computer before running this: %// Load in MATLAB logo Without further ado, here's the code you should use. Once we finish mixing the stuff together, we then cast this part of the image back to uint8, as that is what the original type of bigger image was. We need to make sure that when you are multiplying two matrices together, they must be the same type. One final note: We need to temporally convert the type of each image to double as the alpha maps are now double. We will also need to know the dimensions of this resized image so that we can properly put this into our bigger image. You can use im2double to do this for us.įinally, we can use imresize to scale the image down so that it is 10% original size. As such, we need to transform the alpha map so that it spans between. Before we can even do this, the alpha channel returned from imread actually (it's usually.) an unsigned 8-bit integer type image which has its alpha values span from. In our case, im1 is our MATLAB logo, while im2 is Jack Bauer. Im1 is the image you want to mix in, while im2 is the image where im1 will be placed on top of this image. If you want to mix two images together, given an alpha channel, you do it this way: out = alpha*im1 + (1-alpha)*im2 Once we have this, we can finally mix in the logo with the image. This can be done by simply replicating the alpha map 3 times, and stacking it into a 3D matrix. As such, we want to mix all of the colours together, and so we need to make the alpha channel a 3D matrix. Now, the alpha channel is only a single 2D matrix, while the MATLAB logo and Jack Bauer are colour images. The second parameter is the colour map, but let's ignore that as we don't need it for what you want to do. Specifically, we need the third parameter. You can use imread as you have said, but we need to specify additional output parameters in order to grab the alpha channel. This is great because we will need the alpha channel so that we can place the MATLAB logo while making it look natural. Keep in mind that this MATLAB logo is in PNG format, which means that it will have a transparency / alpha channel. Once we do this, we simply have to replace those pixels that are in the top left corner with the MATLAB logo. Let's resize this down to 10% of the original size. The MATLAB logo is quite large, so we're going to resize it so that it's a small icon. Here's the picture of Jack Bauer I'm going to embed the MATLAB logo in: Here's an example MATLAB logo from the Wikimedia Commons media archive: Let's say I want to embed the MATLAB logo in the top left corner of a snapshot showing fictional federal agent, turned rogue: Jack Bauer. is on the right track, but I want to produce an example that works.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |