From: Caio on 2 Mar 2010 07:00 Good morning. I wonder how I can use the function imellipse to create a mask in an image, which is a uint8 image 640x480. The masked image should contain only values of pixels in the selected region, out of this, the values must be zero. When I apply the following routine in my image: >> a=imread('image1'); >> b=imread('image2'); >> ratio=double(a)./double(b); >> imshow(ratio) >> h_ellipse = imellipse(gca,[]); >> api = iptgetapi(h_ellipse); >> vert = api.getVertices(); >> [m,n,unused] = size(ratio); >> mask = poly2mask(vert(:,1),vert(:,2),m,n); >> mask = repmat(mask,[1,1,3]); >> masked_image = zeros(m,n,3,'uint8'); >> masked_image(mask) = ratio(mask); in this last line, an error message appears: "Index exceeds matrix dimensions." How can I solve this problem to my images. Thanks.
From: ImageAnalyst on 2 Mar 2010 07:48 Try my demo instead: It makes an ellipse and puts it into the overlay of the image, then makes a binary mask of it, and finally burns that ellipse into the actual image pixels. Then it does the same for a line. Simply copy and paste the following code. (Be sure to join any lines split apart by the newsreader) % Demo to write an ellipse and a line into the overlay of an image, % and then to burn those overlays into the image. %----- Initializing steps ----- % Clean up clc; clear all; close all; workspace; % Display the workspace panel. % Display images to prepare for the demo. monochromeImage = imread('pout.tif'); subplot(2, 4, 1); imshow(monochromeImage); title('Original Image'); subplot(2, 4, 2); imshow(monochromeImage); title('Original Image with ellipse in overlay'); subplot(2, 4, 5); imshow(monochromeImage); title('Original Image'); subplot(2, 4, 6); imshow(monochromeImage); title('Original Image with line in overlay'); set(gcf, 'Position', get(0, 'ScreenSize')); % Maximize figure. %----- Burn ellipse into image ----- % Create elliptical mask, h, as an ROI object over the second image. subplot(2, 4, 2); hEllipse = imellipse(gca,[10 10 100 100]); % Second argument defines ellipse shape and position. % Create a binary image ("mask") from the ROI object. binaryImage = hEllipse.createMask(); % Display the ellipse mask. subplot(2, 4, 3); imshow(binaryImage); title('Binary mask of the ellipse'); % Let's try to add some text. (Doesn't work) % hText = text(50, 100, 'Line of Text'); % textMask = hText.createMask(); % binaryImage = binaryImage & textMask; % imshow(binaryImage); % Burn ellipse into image by setting it to 255 wherever the mask is true. monochromeImage(binaryImage) = 255; % Display the image with the "burned in" ellipse. subplot(2, 4, 4); imshow(monochromeImage); title('New image with ellipse burned into image'); %----- Burn line into image ----- burnedImage = imread('pout.tif'); % Create line mask, h, as an ROI object over the second image in the bottom row. subplot(2, 4, 6); hLine = imline(gca,[10 100],[10 100]); % Second argument defines line endpoints. % Create a binary image ("mask") from the ROI object. binaryImage2 = hLine.createMask(); % Display the line mask. subplot(2, 4, 7); imshow(binaryImage2); title('Binary mask of the line'); % Burn line into image by setting it to 255 wherever the mask is true. burnedImage(binaryImage2) = 255; % Display the image with the "burned in" line. subplot(2, 4, 8); imshow(burnedImage); title('New image with line burned into image');
From: Caio on 2 Mar 2010 07:50 "Caio " <caiovtrich(a)gmail.com> wrote in message <hmiuk7$cjd$1(a)fred.mathworks.com>... > Good morning. > I wonder how I can use the function imellipse to create a mask in an image, which is a uint8 image 640x480. The masked image should contain only values of pixels in the selected region, out of this, the values must be zero. When I apply the following routine in my image: > >> a=imread('image1'); > >> b=imread('image2'); > >> ratio=double(a)./double(b); > >> imshow(ratio) > >> h_ellipse = imellipse(gca,[]); > >> api = iptgetapi(h_ellipse); > >> vert = api.getVertices(); > >> [m,n,unused] = size(ratio); > >> mask = poly2mask(vert(:,1),vert(:,2),m,n); > >> mask = repmat(mask,[1,1,3]); > >> masked_image = zeros(m,n,3,'uint8'); > >> masked_image(mask) = ratio(mask); > in this last line, an error message appears: "Index exceeds matrix dimensions." > How can I solve this problem to my images. > Thanks. Help me, please
From: ImageAnalyst on 2 Mar 2010 08:01 If you'd run my demo, you'd see that you need to call % Create a binary image ("mask") from the ROI object. binaryImage = hEllipse.createMask(); instead of poly2mask.
From: Caio on 2 Mar 2010 08:31
ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <72015c6c-aa73-489f-b6f8-1394a41c6bbe(a)z35g2000yqd.googlegroups.com>... > If you'd run my demo, you'd see that you need to call > > % Create a binary image ("mask") from the ROI object. > binaryImage = hEllipse.createMask(); > > instead of poly2mask. I send an email to you explain the doubts that i have. Thanks. |