How to mask each region in image within boundary

7 visualizzazioni (ultimi 30 giorni)
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.

Risposte (2)

Gopichandh Danala
Gopichandh Danala il 13 Mag 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 Commenti
amir nemat
amir nemat il 14 Mag 2017
Please see the updated question. You didn't get me question.
Gopichandh Danala
Gopichandh Danala il 28 Mag 2017
Modificato: Gopichandh Danala il 28 Mag 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..

Accedi per commentare.


Image Analyst
Image Analyst il 13 Mag 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 Commenti
amir nemat
amir nemat il 14 Mag 2017
Please see the updated question. You didn't get me question. Poly2mask is not working for this question.
Image Analyst
Image Analyst il 14 Mag 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.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by