find position of image surranded by black area
There is an image, surrounded by black region, I would li开发者_如何学运维ke to find the exact locaton of this image (which is surrounded by black region). I mean the coordinates of four corners of this image. Thanks.
You could apply a second derivative mask on your image which will then accurately pick up the points at which the colour goes from black to the content of the picture. You can then extract the first and last row and column each and you've got your coordinates.
If you are in matlab:
Mask out the black area. Either try:
Image = logical(Image)
Or find the intensity of a black voxel (probably zero) and say:
Image = ind2sub(size(Image), find(Image ~= blackPixelIntensity))
Once you have the binary non-black part of the image (so just the object and not the background), you just want to find the min, max corners of each voxel. Say:
[x y] = ind2sub(size(Image), find(Image ~= 0))
c1 = [min(x) min(y)]
c2 = [max(x) min(y)]
c3 = [max(x) max(y)]
c4 = [min(x) min(y)]
Where c1,...,c4 are your corners :)
Lemme know about any syntax error as I don't have access to matlab atm.
tylerthemiler
Edit: if you simply want the entire perimeter of the non-black part of the image, just do whichever of the first two lines of code above works, and then say:
Imperim = bwperim(Image)
Edit2: Note that Image is the 2D array, you can use whatever you want to load in the jpg :P
精彩评论