필터 지우기
필터 지우기

mask

조회 수: 4 (최근 30일)
Colm
Colm 2011년 10월 20일
I have a image which is uint16, when I take an 'imrect' and create a mask I loose the range of pixel values. They change from 0-65535 to 0-1. How do I specify when creating the mask that it is not binary?
H =imrect;
mask = H.createMask();
rect = uint16(mask);
D = sqrt(0.5);
Dev = std2(rect);
RMS = Dev/D;
Mean = mean2(rect);}
Thanks

채택된 답변

Jan
Jan 2011년 10월 21일
A "mask" is binary in Matlab. It is the mask only! If you want to get the pixel values inside the mask, you either multiply the mask with the image matrix (size remians the same) or use the mask for indexing (result is the masked rectangle only).
Please post your code and explain, what you want to achieve.
  댓글 수: 3
Jan
Jan 2011년 10월 21일
@Colm: The image values do not appear at all in your code. As I've explained already, the "mask" is only a mask, it does not contain any information about the pixel values. If you image matrix is called Img, you need something like:
Cut out masked area: rect = Img(mask);
or
Set pixels outside the mask to 0: rect = Img .* uint16(mask);
Colm
Colm 2011년 10월 21일
I set the values inside the mask to 1. Then pointed the original binary file positions to the mask position and multiplied them.
The image code is:
frame3 = (frame1 - frame2)*1.4142135623730950488016887242097;
fid5 = fopen('DF.bin', 'w');
fwrite(fid5, frame3, 'uint16');
fclose(fid5);
fid = fopen('DF.bin');
samevals = fread(fid, [512, 1024], 'uint16');
fclose(fid);
axes(handles.axes2);
imshow(samevals);

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2011년 10월 21일
See my demo:
clc; % Clear command window.
% clear; % Delete all variables.
close all; % Close all figure windows except those created by imtool.
imtool close all; % Close all figure windows created by imtool.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
% Change the current folder to the folder of this m-file.
% (The line of code below is from Brett Shoelson of The Mathworks.)
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
% Change the current folder to the folder of this m-file.
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
% Display images to prepare for the demo.
monochromeImage = imread('pout.tif');
subplot(2, 3, 1);
imshow(monochromeImage);
title('Original Image', 'FontSize', fontSize);
subplot(2, 3, 2);
imshow(monochromeImage);
title('Original Image with ellipse in overlay', 'FontSize', fontSize);
set(gcf, 'units','normalized','outerposition',[0 0 1 1]); % Maximize figure.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
%----- Burn ellipse into image -----
% Create elliptical mask, h, as an ROI object over the second image.
subplot(2, 3, 2);
hEllipse = imellipse(gca,[70 15 90 140]); % Second argument defines ellipse shape and position.
% Create a binary image ("mask") from the ROI object.
maskImage = hEllipse.createMask();
% Display the ellipse mask.
subplot(2, 3, 3);
imshow(maskImage);
title('Binary mask of the ellipse', 'FontSize', fontSize);
% Mask the image with the ellipse.
maskedImage = monochromeImage .* cast(maskImage, class(monochromeImage));
% Display the image with the "burned in" ellipse.
subplot(2, 3, 4);
imshow(maskedImage);
title('New image masked by the ellipse', 'FontSize', fontSize);
% Find the bounding box
column1 = find(sum(maskImage, 1), 1, 'first')
column2 = find(sum(maskImage, 1), 1, 'last')
row1 = find(sum(maskImage, 2), 1, 'first')
row2 = find(sum(maskImage, 2), 1, 'last')
croppedImage = maskedImage(row1:row2, column1:column2);
subplot(2, 3, 5);
imshow(croppedImage);
title('Ellipse portion cropped out', 'FontSize', fontSize);

카테고리

Help CenterFile Exchange에서 Build Interactive Tools에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by