[Top] [Up] [Prev] [Next] [Up] [Tutorial] mmtutor V1.0 30abr2001

mm015union - Union.


Synopsis
mm015union
Description

Union of two synthetic images

In the following, we have an interesting visualization of the union of gray-scale images. The sequence of commands below present the union of the two synthetic images.

f1=uint8(repmat( ones(15,1)*[1:15], 3 ));
f2=uint8([1:45]' * ones(1,45)/3);
f3=mmunion(f1,f2);
mmshow(f1);
mmshow(f2);
mmshow(f3);
image
(f1)
image
(f2)
image
(f3)

Requirement of operands with same data type

The next example presents the union of a binary time signal, converted to the intensity range [0,255], with another time signal.

The union requires that both images are of same data type. It is shown below the result when the images are not of the same type and mmfreedom is 0, i.e., no automatic data type conversions are allowed:

mmfreedom(0); % put the toolbox in no automatic data type conversion mode
f_bin  = mmbinary(uint8([1   1   0   0  1   0]));
f_gray = uint8( [0 100 150 120 30 200]);
mmunion(f_gray,f_bin)
??? automatic conversion from logical binary uint8 to uint8 is not allowed (see MMFREEDOM)
mmunion - Invalid input par: f2.

If we allow automatic conversion with warning, by changing the mmfreedom value to 1, the binary image is automaticaly converted to uint8 gray-scale by a simple casting. Note that value of the first pixel as 1.

mmfreedom(1);  % put back in automatic conversion mode with warning
mmunion(f_gray,f_bin)
warning: converting from type  binary uint8 to uint8
ans =
     1   100   150   120    30   200

The proper way of doing this is by using an explicit convertion from binary to gray-scale image using the mmgray function. In this case the 1 values are converted to 255.

f_bin  = mmbinary(uint8([1   1   0   0  1   0]));
mmgray(f_bin)

ans =
   255   255     0     0   255     0
mmunion(f_gray, mmgray(f_bin))

ans =
   255   255   150   120   255   200

Processing in a Region of Interesting (ROI)

The next example presents the overlay of a binary image (representing a word) on a gray-scale image. The binary image has a domain smaller than the gray-scale image. The sequence of commands below correspond to the following actions: extraction of a region of interest of the gray-scale image with the same domain of the binary image; conversion of the binary image in a gray-scale image; union of the two images created; inclusion of the resulting image in the original image. The figure below presents the result of this procedure.

f1 = imread('ggray.tif'); % gray-scale input image
mmshow(f1);
f2 = mmtext('Simple');    % binary image with text
mmshow(f2);
h = 50:49+size(f2,1);     % ROI height
w = 1:size(f2,2);         % ROI width
f1(h,w) = mmunion( f1(h,w), mmgray(f2));
mmshow(f1); 
image
(f1)
image
(f2)
image
(f1)

Combining two images

The next example presents the construction of an image from two input images (upper and lower case letters presented, respectively, in the first and second figures, and a template image (presented in the third figure). The template is used to select if the pixels come from the lower case or upper case images. If a pixel in the template is 1, an upper image pixel is selected, otherwise a lower case image pixel is chosen.

The function mmtext is used to build the letters. The template is built by a composition of constant 0 and constant 1 images, that are built, respectively, by the subtraction of two same letter images, and its complement. In this way fzero and fone images are of the same size of a letter image.

The resulting image is presented in the fourth figure below:

f1 = mmtext('ABCDEF'); % input image 1
f2 = mmtext('abcdef'); % input image 2
fzero = mmsubm(mmtext('A'),mmtext('A')); % zero template
fone  = mmneg(fzero); % one template
f3 = [fzero fone fzero fone fzero fone];
f4 = mmunion(mmintersec(f1,f3),mmintersec(f2,mmneg(f3)));
mmshow(f1);
mmshow(f2);
mmshow(f3);
mmshow(f4);
image
(f1)
image
(f2)
image
(f3)
image
(f4)

Exercises


[Top] [Up] [Prev] [Next] [Up] [Tutorial] Valid XHTML 1.0!
Copyright (c) 1998-20001 by SDC Information SystemsCopyright (c) 1998-20001 by SDC Information Systems