I want to display an image and allow mouse over to show pixel values- as in impixelinfo function.
The thing is- I show the image on an inverse scale (1./image) but want the shown values to be the original ones.
Is there some way to do it?
A possible workaround - puts your original image over the top as a transparent layer, leaving the visible image (1./image) for the user and an invisible image which impixelinfo takes its data from.
imshow(1./image);
hold on
h = imshow(image);
set(h, 'AlphaData', zeros(size(image)));
impixelinfo
Related
I have an image subdivided into slic superpixels. I'm using the gui to select some of these superpixels.
Now I want to highlight the selected superpixels as transparent tiles.
However I only know how to either a) use an mask to suppress parts of the overlay image or b) how to set the entire overlay as tranparent.
a)
imshow(superPixelImage)
hold on;
h = imshow(overlayImage);
set(h,'AlphaData',overlayMask);
b)
imshow(superPixelImage)
hold on;
h = imshow(overlayImage);
set(h,'AlphaData',0.5);
Does someone know how to combine both such that the overlay is fully transparent on the non selected area and partly transparent on the marked superpixels?
Edit:
This is a beta-version of my matlab code that can be used to create semantic labels for an image database.
You can insert a matrix that match the size of your image to fill the 'AlphaData' parameter.
imshow(superPixelImage)
hold on;
h = imshow(overlayImage);
AlphaMatrix = (~im2bw(overlayImage)>0)*0.5 %creation of your AlphaMatrix.
set(h,'AlphaData',AlphaMatrix);
I have a gray image. I would like to add two markers to the image. In which, a marker is blue mark withi color code (0000FF) and other marker is red mark FF0000. Could you help me to add this mark in the gray image using MATLAB? Note that, each marker has shape is rectangular shape. Thanks
This is my input and my expected output
The original image can be download at here
Use the rectangle function to apply the mask. Now for saving the figure in desired size, you could set the PaperPositionMode to manual and get the desired image size. The code below also shows different ways to save the figure in different formats.
[A, cmap1] = imread('11.bmp');
imshow(A,cmap1);
hold on;
rectangle('Position',[45,45,20,10],'EdgeColor','r','FaceColor','r');
hold on;
rectangle('Position',[50,80,30,10],'EdgeColor','b','FaceColor','b');
hold off;
f = getframe();
imwrite(f.cdata,'myfigure.bmp');
Here is the resulting image:
Use the insertShape function in the Computer Vision System Toolbox.
I have two plots I want to overlay on top of each other as shown in the link below:
The inputs are the two images on the left and the output is the image on the right. Here's the code I used:
reference = imread('ref_foam.png');
figure, imshow(reference);
hold on;
h = imshow(data,[]);
hold off
colormap jet;
alphamap = zeros(size(reference,1),size(reference,2));
for i = 0:size(data,1)-1
for j = 0:size(data,2)-1
if(~(data(i+1,j+1) == 0))
alphamap(i+1,j+1) = 0.75;
end
end
end
set(h, 'AlphaData', alphamap);
Anytime there's a zero in the data array, it sets that transparency to zero or else it will set the transparency to 0.75.
Now, my questions are: How can I get the colormap to apply to only the data array? In this example it works but if I convert "reference" to a grayscale, the colormap applies to that as well. The input for the colormap is an axes handle, is there anyway to input the image's handle (h) so that it only applies to the top (data) array? Also, I'd like to implement a colorbar as well. Is there anyway to apply the colorbar only to the data array? Thanks.
You probably want to use the subimage command - it lets you create images on the same figure with different colormaps.
Once create and modified as in your script, overlay the images by setting their axes positions on top of each other.
I have a large plot showing an image. Now, I want to diplay several small bar plots on top of that image, each having its own axes and positioned on a specified position on the image.
I already tried to just append more axes (with transparent background color) to the same figure. This basically works, but If I now zoom in or pan around the background image, the small axes stay on the same position relative to the figure, so they lose the relation to their position on the background image.
Does Matlab offer a better solution?
I recommend drawing the bars using patch command.
For example:
plot(rand(10));
hold on;
patch([1;1;2;2],[1;2;2;1],'r')
I would like to crop an image but I want to retain the part of image that is outside of the rectangle. How can this can be done?
It seems that with imcrop only the part within the rectangle can be retained.
An image in Matlab is represented by a matrix, just like any other matrix, you can read more about representation forms here.
It seems that what you want to do is to take the area that you don't want and change the values of the corresponding cells in the matrix to the color that you want to put instead (each cell in the matrix is a pixel in the image). That is if you know the place where your unwanted data is.
If you don't know where it is, and want to use the tool given by imcrop to manually choose the "cropped" area, you can take the resulting matrix, and find the part of the original image which is an exact match with the cropped part, and to color it as you wish.
The code for doing this:
I=imread('img_9.tif');
I2=imcrop(I,[60,50,85,85]);
n_big=size(I);
n_small=size(I2);
for j1=1:(n_big(1)-n_small(1))
for j2=1:(n_big(2)-n_small(2))
Itest=I(j1:j1+n_small(1)-1,j2:j2+n_small(2)-1,:);
if ( Itest == I2)
I(j1:j1+n_small(1)-1,j2:j2+n_small(2)-1,:) = zeros(n_small(1),n_small(2),3);
end
end
end
figure(1);
imshow(I);
figure(2);
imshow(I2);
The results of my test were:
original:
cropped:
resulting image:
maybe what you want to do is first a mask with the inverse area of what you want to crop and save this result.