How to mask each region in image within boundary
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Gopichandh Danala
am 13 Mai 2017
% 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 Kommentare
Gopichandh Danala
am 28 Mai 2017
Bearbeitet: Gopichandh Danala
am 28 Mai 2017
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
am 13 Mai 2017
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 Kommentare
Image Analyst
am 14 Mai 2017
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.
Siehe auch
Kategorien
Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!