resize and save transparent PNG file in matlab - matlab

I have an transparent png file(colored image not black and white).I want to resize this png file and save that with transparent background.but i cant save that with transparent background.file saved with dark background.
[im,map]=imread('image.png');
im=ind2rgb(im,map);
im2=imresize(im,[200,200]);
imwrite(im2,'image2.png');
in above code image2.png saved with black background and not transparent

Additionaly you have to read the transparency (alpha) value of the Image. Then you have to scale that value as well. Then you can write the Image with the alpha value.
[im, map, alpha] = imread('image.png');
im2=imresize(im,[200,200]);
resizedAlpha = imresize(alpha,[200, 200]);
imwrite(im2, 'image2.png', 'Alpha', resizedAlpha);

Related

how to display dicom image in matlab always with black background ?

I have a problem with some dicom images. Maybe they have a different image range.
Generally it display as normal with black background but sometimes it display with white background. I have a question : what can I change it ? I would like to display images always with black background.
I would appreciate for any help/advice. I don't know what I should change ?
Agata
Please check the value of Photometric Interpretation (0028, 0004). This specifies the intended interpretation of the image pixel data. If the value is “MONOCHROME1” than the minimum sample value of pixel data is intended to be displayed as white (after any Modality LUT transformation) and maximum pixel value as black (inverted grayscale image)

saveas white border matlab

I want to save a frame as an image in png format with saveas command. Although my image's size is 640X480 (gcf), the saved images size is 1201x901 and spaces white color.(like a bold white border).So I want the image to be saved 640x480.
I tried transparent background but it didn't work. How can I fix this problem?
F(j) = getframe(gcf);
fname='C:\...'
saveas(gcf, fullfile(fname, 'newImage'), 'png');
Try this,
set(gca,'position',[0 0 1 1],'units','normalized')
or you can try the imcropfunction.
If you aren't overlaying any graphics over the image, then save the image data directly using imwrite, rather than exporting a figure containing the image to png.
If you are overlaying graphics then the export_fig function (available for download on the MATLAB File Exchange) will automatically crop the whitespace around the figure. In this case use:
export_fig(fullfile(fname, 'newImage'), '-png', '-a1', '-native');

iphone: How can I remove the red colors from an image? (RGB colors)

Let's say I have an UIImageView, and I wanna show only blue and green colore from it, (RGB colors). Like in Photoshop, I can choose what colors to show, red, blue, and green, so in the image to delete the red color.
So how can I do it? I really new in Objective-c and all :)
There are many ways to do this. If you have access to the image bitmap data, you can just set the red channel to zero on all the pixels. You might need to draw the image into a CGBitmapContext, get the pointer to the bitmap data, and then create a new CGImage that gets turned into a UIImage.
Or you can create a UIView subclass with a custom drawRect: method which first draws the image normally, and then draws a color set to RGB (0, 1, 1) with the blend mode (set by CGContextSetBlendMode) to kCGBlendModeMultiply.

How do I get a colored texture brush to show up in Open GL ES on white background?

I want to draw with a texture brush, in a color of my choice, on a white background using OpenGLES.
I have a bitmap image which I use CG to load and turn into a texture. This bitmap is mostly black, but has a white circle in the center that I want to use as the "brush". In other words, I want the black part to vanish in the final compositing, but the white part to take on the color that I set using glColor.
The best I can get is with the blend parameters (GL_SRC_ALPHA, GL_ONE) after setting some opaque bright color is a faded color line on a grey (not pure white background). But when I set the background to pure white, the line isn't visible.
At least in the current situation, the black edges of the original texture don't appear. Most other blend combinations I'm trying cause either nothing to show up even on grey, or to see the entire brush including the black edges, which is no good.
Is anyone willing to explain to me how I should set up my texture and/or GL states to make the bright color show through on pure white, without showing the black texture edges at all? This might be a newbie question, but I've tried working through the blend math, and I still just don't understand how the colors are all being factored together.
Here's the image I'm using as the brush:
alt text http://www.coldcoffeeandjuice.com/OpaqueBrush.png
Here's some resulting output, when the background is grey, and the glColor4f is set to (1, 0, 0, 1), eg pure red, and the brush is used on a bunch of consecutive GL_POINTs. Note that what's good about this is that only the white part of the brush image shows the color red-- that's right. The bad parts is that the red which I want to be pure and bright is pale due to being blended with the background (?) and/or the white of the brush (?) so that it washes out entirely if the background is pure white. This uses the blend params as given above (src_alpha, one).
(source: coldcoffeeandjuice.com)
Here's what I want to see, given the pure red color (thanks Paintbrush):
(source: coldcoffeeandjuice.com)
Can anyone help me understand what I'm doing wrong?
Thanks!
Ok, so you're trying to "paint" a given colour (in this case "red") on to a background, using a mask for the brush shape.
You need to do the following before you start rendering the "paint":
First make sure your brush has an alpha channel that corresponds with its shape - that is the alpha channel should look similar to the brush image you posed.
Render with these states set (note space to get around wiki markup):
// Make the current material colour track the current color
glEnable( GL_COLOR_MATERIAL );
// Multiply the texture colour by the material colour.
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
// Alpha blend each "dab" of paint onto background
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
See also:
http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/colormaterial.html
http://www.khronos.org/opengles/documentation/opengles1_0/html/glTexEnv.html

How do I use a mask to punch out my image?

I have a mask (loaded from a 256 grey PNG) that I want to apply to an image that's being used as part of my process for drawing a UITableViewCell's imageView.image property.
When the cell isn't selected/highlighted, I CGImageCreateWithMask with a square of the proper color and the mask, then drawAtPoint: it into the image I'm building. This works fine.
However, when the cell is selected or highlighted, I'd like to instead use the mask to instead punch through my image appropriately. That is, when my mask specifies full opacity, I want the image I'm building to be completely transparent so the tableview's background is drawn through it. Where my mask specifies 0 opacity, I want the alpha channel untouched. I want nothing other than the alpha channel affected.
I guess what I mean is that I want to draw clearColor over a UIImage, with a varying level of opacity according to a mask.
First, what is this called? And second, how do I do it?
I think you have to manipulate the CALayers for that. You can use the mask property of the cell's CALayer : CALayer mask attribute.
That is, something in the way of (if myMask is descendent of UIView) :
myCell.layer.mask = myMask.layer