Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If your roi is rectangular, just loop over the appropriate subsection of the image rather than the whole thing.</p> <p>If not, and you can define the watermarking as some function:</p> <p><code>imgout = watermark(img1, img2);</code></p> <p>Then you can use <code>roifilt2</code> to apply that function just in your roi. </p> <p>In this simple example,<code>mask</code> is a BW matrix where 1 indicates part of our roi (a mask can be created several different ways including using some of the interactive roi functions, see bottom section). <code>img1</code> and <code>img2</code> have already been loaded:</p> <pre><code>f = @(x) watermark(x,img2); % our very basic function imgout = roifilt2(img1,mask,f); </code></pre> <p>Complications may arise if your <code>img2</code> is smaller than <code>img1</code> (or if you want to resize it to just cover the roi area). In this case, do everything on a subsection of img1/mask and then assemble the final image:</p> <pre><code>img1_s = img1(a:b,c:d); % these return the same size as img2 mask_s = mask(a:b,c:d); imgout_s = roifilt2(img1_s,mask1_s,f); imgout = img1; imgout(a:b,c:d) = imgout_s; </code></pre> <hr> <p>A mask can be created several ways, some using the interactive roi functions, some not. A lot depends on how you have your roi in the first place - do you have a centre/radius, or do you want to hand-pick the location interactively, etc. Here are a few examples making use of the Image Processing Tool Box:</p> <p><strong>Interactive ROI function and createMask.</strong></p> <p>This will work for any of the interactive roi functions (imellipse, imfreehand, etc). You can interactively adjust the mask between the second and third steps. Do not close the image window before calling <code>createMask</code>.</p> <pre><code>h = imshow(img); %display image e = imellipse(gca,[50 50 100 100]); % select roi mask = createMask(e,h); % return mask </code></pre> <p><strong>List of x/y points and poly2mask</strong> If you have a list of points defining the outer edge of your roi, a quick non-interactive way of producing a mask is to use poly2mask. The third and fourth values define the total size of the mask returned.</p> <pre><code>mask = poly2mask(x,y,size(img,1),size(img,2)); </code></pre> <p><strong>Using morphological operators</strong> <code>strel</code> defines a structuring element, and <code>imdilate</code> performs a dilation using that structuring element. Given an image which contains a single point, what that does is replace the point with the structuring element - in this case <code>disk</code> which will produce a circle (or as close as you can get using pixels). Other shapes (e.g. <code>diamond</code>) can be used with <code>strel</code></p> <pre><code>mask = zeros(size(img)); mask(a,b) = 1; % a,b is the centre point of the circle se = strel(disk,r,0); %r is the radius of the circle mask = imdilate(mask,se); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload