How to find the dimensions of a specific area in an existing image?

2 vues (au cours des 30 derniers jours)
Alexander West
Alexander West le 9 Avr 2019
Say I'm given an image with a rectangular space made entirely of green pixels. I want to find the dimension of that area that is made entirely of green pixels.
This is what I have so far:
numGreenPixels=img(:,:,1)==0 & img(:,:,2)==255 & img(:,:,3)==0
numGreenPixels = sum(numGreenPixels(:));
this would only given me the total number of green pixels, when I need to find the dimension of said space. How do I go about this?
  2 commentaires
KSSV
KSSV le 9 Avr 2019
when I need to find the dimension of said space.
YOu can find the dimensions if you can arrange the data into a matrix form......is your green region a square/ rectangle? If it is taking some other irregular shape, how you will specify the dimensions?
Alexander West
Alexander West le 9 Avr 2019
It is always a rectangle/square, sorry if I didn’t specify.

Connectez-vous pour commenter.

Réponses (1)

KSSV
KSSV le 9 Avr 2019
Modifié(e) : KSSV le 9 Avr 2019
In that case......the length of unique of x,y should give you the dimensions. You have numGreenPixels as a matrix of 0 and 1's.
[y,x] = find(numGreenPixels) ;
If it is not clear attach your image.
  1 commentaire
Alexander West
Alexander West le 9 Avr 2019
function refrigerator(fridge,picNeed)
img=imread(picNeed)
background=imread(fridge);
r=(img(:,:,1))
g=(img(:,:,2))
b=(img(:,:,3))
numGreenPixels=img(:,:,1)==0 & img(:,:,2)==255 & img(:,:,3)==0
[y,x] = find(numGreenPixels) ;
background=imresize(background,[x,y])
[w,r] = strtok(fridge,'.')
newFile= ['decorated_' w r]
imwrite(img,newFile)
end
Doing this returns an error with the resize function? Logically, it should work right?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Read, Write, and Modify Image dans Help Center et File Exchange

Tags

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by