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);
Related
I'm working with leaves' images in matlab. I will compare portions of those leaves through some similarity functions (euclidean for example), but first I need to extract portions of each leave and then save them. So, this is my problem now: how do I select those portions and draw a rectangle that shows me what will be cut? I already got the centroid and a boundingBox by using regionprops function (you can see those in red in the image firstResultsMatlab.png). However, I'm struggling by trying to draw and extract portions like those that are in blue (same image). I don't want to get parts from the black background, only portions from the leave.
I've also added an images of leaf as an example of what I've been working on and the code I used to get a boundingBox and the centroid. Any ideas are welcomed!
Thank you very much in advance.
I = imread('C:\Users\IBM_ADMIN\Desktop\Mestrado\Imagens_Final\IMG1_N1_1.png');
L = bwlabel(I);
s = regionprops(L,'BoundingBox');
stat = regionprops(L,'centroid');
hold on;
colors = hsv(numel(s));
for k = 1:numel(s)
him = imshow(I);
hold on;
rectangle('Position', s(k).BoundingBox, 'EdgeColor', colors(k,:));
plot(stat(k).Centroid(1),stat(k).Centroid(2),'rx');
end
matlab-results
leaf-1
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 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
just as the picture above shows ,I have get the boundarys of one image after
segmentaion . But I just get the logical boudarys and I want to label each
region that splited by segmentaion. function bwlabel doesn't work ,It can only
label connected region. so ,how can I label these two hundred regions ???
If your original image is called img and your current bw segmented image is called I, I would suggest:
I = (I==0); % invert the image
cc = bwconncomp(I,8); % could use 4-connected neighborhood also
s = regionprops(cc,img,'all');
The last line will provide all the available properties from the original image for each segmented region (if you want it). You could use bwlabel as you mentioned, but I think bwconncomp may be faster/more efficient.
An alternative to bwlabel for labeling is:
L = labelmatrix(cc);
Then I like using label2rgb to view the segments:
RGB_label = label2rgb(L, #jet, 'k', 'shuffle');
imshow(RGB_label);
This will randomly color each segment according to the colormap provided (jet, in this case).
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.