Image processing - TIFF images in Matlab in grayscale - image

In Matlab, when I use
imshow('trees.tif')
it displays an RGB image, but when I use these two functions
I=imread('trees.tif')
imshow(I)
it displays a gray scale image, and it's still the exact same image.
This only happens with TIFF images, because when I use it for a JPEG image like so:
I=imread('flower.jpg')
imshow(I)
it displays an RGB image, and it's the same thing as imshow('flower.jpg').
Can anyone please explain why the use of imread/imshow on TIFF images displays them in gray scale?

Load the color map too:
[I,cmap] = imread('trees.tif');
Display it with the map:
imshow(I,cmap)
Convert it to RGB:
Irgb = ind2rgb(I,cmap)
So you can display and manipulate it without the colormap:
imshow(Irgb)
imagesc(Irgb)
% etc.
Eye candy:

Related

Can not display a png image file which is modified from a svg file in MATLAB

I tried this code to modify svg image to png
filename = 'hello';
inkscapepath = '"my inkscape path"';
system( [inkscapepath ' ' filename ...
'.svg --export-area-drawing --export-png=' filename '.png'])
It will create a hello.png file.
If I open it with windows picture viewer it is looking fine.The same content is present.
svg image is in png form but resolution changed from 100x100px to 60x8.
But to view it in MATLAB if use
imshow('hello.png')
A fully black image is coming as output figure.
the image matrix contains all the entries equal to 0
This answer is based on a guess that the file only contains a black image on a transparent background
Such as this one:
-it's in a spoiler to show transparency
With imshow Matlab replaces transparent pixels with black, to avoid this we can use imread to load in the image with additional options to set transparent pixels to white and then use imshow
RGB = imread('hello.png', 'BackgroundColor', [1,1,1] );
imshow(RGB);
Figure from passing the filename to imshow
Figure from setting transparent pixels to white

read image but show strange colour

I have read a image like that
a = imread('test.jpg');
image(a)
what the test.jpg is:
but after the image function
the result is:
and I don't know why it show that?
Because I want to crop some part, so I have to see the image shown.
How to fix it by showing the human face by image?
You are using image command to display an image. From here: "image creates an image graphics object by interpreting each element in a matrix as an index into the figure's colormap or directly as RGB values". Since you are providing a 2-D matrix, each element is interpreted as the index to the figures colormap. You can see the figure's colormap by using
c_map=colormap;
Also, the axis is set to square, therefore you see a circle instead of an ellipse. Use imshow(a,[]) to display the grayscale image as desired.
You image data might be in a color map instead. try [a,cmap] = imread(...). If cmap is not empty, a is indices into cmap, and cmap contains the actual colors.
Use img = cat(3,cmap(a,1),cmap(a,2),cmap(a,3)) to get your image, and show it with image(img).
Note that using imagesc might be misleading in this case as it will still show something that looks like your image when simply doing imagesc(a). This as different pixels colors are associated with different index-values in a.

Resizing a png image without losing tranparency

I am trying to save a png file in database using C#.
Bitmap thumbnail = new Bitmap(file.InputStream);
thumbnail = ImageUtilities.ResizeImage(thumbnail, Convert.ToInt32(width),Convert.ToInt32(height)); ImageUtilities.SaveJpeg(path,thumbnail,Convert.ToInt32(Resources.AppConstants.ExtractThumbnailQuality);
The image gets saved in database, but with a black background around the image. In short, it loses its transparency.
If I skip the resizing of image, instead of black background, a white background appears around the image.
Can anyone suggest, how to preserve the tranparency of the image
You are saving the resized image as JPEG. JPEG does not support transparency. Save it as PNG instead

In matlab, colormap has no effect on image

I am trying to convert an image I have to have a concentration-ish look using matlab. I want it show a range of concentration values for the green part of the image, shown below:
I load in the image and try to change the color map:
>> ex1 = imread('C:\Users\Tyler\Documents\Dropbox\ex1.png');
>> imshow(ex1)
>> colormap(grey)
This changes what the colorbar looks like, but has absolutely no affect on the image itself. It is still green with the purple below it. Why does this not change the image, in the way that just changing the colormap in documentation does.
Tyler
The colormap only has an impact on monochrome data. Presumably it's an RGB PNG file, so it will have no effect here. Use rgb2gray on ex1 first.
If the image is an RGB PNG file you can extract just one channel (red: ex1(:,:,1), green: ex1(:,:,2), blue: ex1(:,:,3)) and plot it using imagesc(ex1(:,:,1)). Now it should be possible to choose your favourite colormap.

Ruby / RMagick rotate and combine images

I'm trying to rotate an image before composing it ontop of another, using RMagick with ruby. I can compose the overlaid image but when I try to rotate the image parts of the background are removed, like so...
Im not sure which CompositeOperator I should be using, or if this is the wrong approach all together?
image = Magick::Image.read("img.jpg").first
overlay = Magick::Image.read("./overlay.png").first
overlay.rotate!(9)
image.composite!(overlay, 100, 50, Magick::OverCompositeOp)
image.to_blob
Before rotating set your background to none:
overlay.background_color = "none"
Other possible methods to use after the rotation:
img.transparent_chroma(low, high, opacity=TransparentOpacity, invert=false)
img.transparent(color, opacity=TransparentOpacity)
so in your case:
overlay.transparent!("white")
you need to set the image transparency with the :opacity parameter
http://alternateidea.com/blog/articles/2005/9/19/custom-image-overlays-with-rmagick
http://www.ruby-forum.com/topic/119556
http://www.rhinocerus.net/forum/lang-ruby/63271-transparent-image-using-rmagick.html
RMagick: Convert CMYK EPS to RGB PNG maintaining transparent background

Resources