How to mask each region in image within boundary
4 次查看(过去 30 天)
显示 更早的评论
I would like to compute some factor inside the a boundary. I have the coordinates of this boundary. I must use a rectangle which each iteration is moving though the image.
0 个评论
回答(2 个)
Gopichandh Danala
2017-5-13
% lets assume you have the cordinates of the rectangle..
% a..like 4 vertices of the rectangle...
img = imread('peppers.png');
figure, imshow(img,[]), title('Original Image')
% I am selecting vertices of rectangle...
% we need just two diagonal vertices to get four coordinates
[tempverticesX, tempverticesY] = ginput(2);
tempverticesX = round(tempverticesX);
tempverticesY = round(tempverticesY);
% Get a masked Rectangle for the given cords
maskRegion = zeros(size(img));
maskRegion(tempverticesY(1):tempverticesY(2),tempverticesX(1):tempverticesX(2),:) = 1;
figure, imshow(maskRegion,[]), title('Mask Region')
% I am assuming you need to map pixel values not just 1's or 0's
% mappedRegion = zeros(size(img));
mappedRegion = uint8(maskRegion) .* img;
figure, imshow(mappedRegion), title('Mapped Region')
If you have any others doubts ask me.
2 个评论
Gopichandh Danala
2017-5-28
编辑:Gopichandh Danala
2017-5-28
amir, as image analyst said your description is not clear, explain clearly the requirement and what you meant by some factor inside the boundary. Do you have a region mask already and you need a factor or you have some rectangle cords and you need get a mask, then find some features (factors)..?
Maybe explain some details..
Image Analyst
2017-5-13
Use poly2mask(), then multiply the mask by your image or use it as a logical index
mask = poly2mask(x, y, rows, columns);
maskedImage = grayImage; % Initialize
maskedImage(~mask) = 0; % Blacken outside of the mask.
Now do your other processing.
2 个评论
Image Analyst
2017-5-14
It's still not clear what you want. Can you get a native English speaker to describe it? I mean, maybe you want to know about the conv2() function that moves a rectangular filter window across the image. Or maybe you don't want that blue boundary line in the image. Who knows???
And we still don't know what what "factor" you want to compute when you say "would like to compute some factor". How about the mean intensity? How about the standard deviation? How about the entropy? How about the number of roads or houses in the region? Who knows? I certainly don't. You didn't tell us.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!