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.
Related
I'm trying to translate an image read through imshow function, but the output is a black image.
Here's the code:
fingers=imread('thumb-index.png');
[nrows,ncols] = size(fingers);
RI = imref2d(size(fingers));
h = imshow(fingers,RI);
grid on
x_center=ncols/2;
y_center=nrows/2;
x_orig=ncols-x_center;
y_orig=nrows-y_center;
[fingers_translate,RF]=imtranslate(fingers,RI,[x_orig,y_orig]);
figure
h=imshow(fingers_translate,RI);
grid on
My target is translating the origin of coordinate system in the center of the image.
Thanks!
you pushed the image out of frame. To see translation effect try:
x_orig=100;
y_orig=100;
I am new in matlab GUI. I want to drawing lines by dragging the mouse. I found this issue but I want save new image with drawn lines. If i run this line, it will show me the same image.
imshow(im);
How can I get new image with drawn lines and for example show it?
You can also grab the image data directly in the Command Prompt. Once you draw all of your lines on your figure window, you can use getframe, which takes a snapshot of the current frame in focus. In this case, this should be your image with the drawn lines. When you call getframe, this will give you a structure with an element called cdata. This will give you an RGB array of what was seen in the figure (without the menu bars... just the figure data itself).
Example:
im = imread('cameraman.tif');
imshow(im);
h = getframe;
out = h.cdata;
figure;
imshow(out); %// Should give you the same image as the figure
You can use print to print the figure to some file. Not sure if you want to have exact reproduction of your line and image. In this case the best way probably would be to store the coordinates and properties of the line and use that to draw it on the image when you want to display it again later.
i'm trying to use masking on an image in order to set a part of the image to be transparent.
from what i've read , it's supported by the SWT library , but i can't find a way to do it . i can't find even an example for that .
i've therefore created my own way to do it , by implementing the masking part :
first i find an RGB value that isn't taken anywhere on the image , and then i set it to be the transparency color. then i take the masking image , and use it to put the correct pixel (either transparent or taken from the source image) in order to create a new image.
it works , but i wish i had a simpler method .
can anyone please help?
This constructor on the Image class looks to do the job:
public Image(Device device,
ImageData source,
ImageData mask)
from the javadoc...
Constructs an instance of this class, whose type is SWT.ICON, from the two given ImageData objects. The two images must be the same size. Pixel transparency in either image will be ignored.
The mask image should contain white wherever the icon is to be visible, and black wherever the icon is to be transparent. In addition, the source image should contain black wherever the icon is to be transparent.
Parameters:
device - the device on which to create the icon
source - the color data for the icon
mask - the mask data for the icon
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.
In Mac OSX,
I have an image with black pixel in all 4 directions.
I want to programmatically crop the image to the maximum image rect.
Should i check for the black pixel and then create the crop rect or is there any supported API is there?
Create an NSImage of the desired size, lock focus on it, draw the desired crop rectangle of the source image into the whole bounds of the destination image, and unlock focus. The image you created now contains the crop from the source image.
Note that this will lose information like resolution (DPI), color profile, and EXIF tags. If you want to preserve those things (probably a good idea), use CGImage:
Use CGImageSource to load the image. Be sure to recover the properties of each image from the file, as well as the images themselves. And note that I used the plural: TIFF files can contain multiple images.
Use the CGImageCreateWithImageInRect function to crop out the desired section of each image. Don't forget to release each original image as appropriate.
If you want to write the cropped-out images to a file, do so using CGImageDestination. Pass both the images and the attributes dictionaries you obtained in step 1.