Drawing Transparent Object

In one of the previous post (Drawing Shapes by Overwriting Pixel Value), a method of drawing transparent object had been illustrated using "Overwriting Pixel Value" technique. In this example, another method will be introduced without overwriting pivel value, but drawing a "Patch" on top of the image.

1. Original image

S = imread('pic12.jpg');
S = im2bw(S);
S2 = S;
imshow(S2);


2. Define transparent object properties

transparency = 0.5;
facecolor = [0 1 0];
edgecolor = [0 1 0];

3. Creating and drawing transparent object

x = [0 20 20 0];
y = [0 0 20 20];
z = [1 1 1 1];
tcolor(1,1,1:3) = facecolor;

h = patch(x,y,z,tcolor,'FaceAlpha',transparency,'edgecolor',edgecolor);


4. To move the object, simply set the "Xdata" and "Ydata" of the object without deleting current object and redrawing a new onject

set(h,'Xdata',x+20);
set(h,'Ydata',y+20);