How can I resize an image from the center?\
Hello! I have a contour, and I want to resize this contour and then draw the resized contour in same image, In another words, I want to create an external contour to the existent one. To this I need to resize the contour mask. however, when I draw both I'm in trouble, because the resized one it is not centered. How can I make the resize from the image center?
height, width = lA1innerContourmask.shape[:2]
nwid =int( 1.5 * width)
nh = int(1.5 * height)
res = cv2.resize(lA1innerContourmask,(nwid, nh),0,0, interpolation = cv2.INTER_CUBIC)
# find contour of the resized
resizedcontour, hier_ = cv2.findContours(res,cv2.RETR_CCOMP,
cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(lA1innerContourmask,resizedcontour,-1,(0,0,255),1)
outax = np.hstack([lA1innerContourmask])
plt.imshow(outax, 'gray')
plt.show()
I think you are doing it in a complicated manner. Have you seen this?
Yes I have seen. The principles are the same. The problem is the image center. If I put a scalled contour over the original one they not alligned. The center is not the same, like this:https://dl.dropboxusercontent.com/u/710615/figure_1.png
I "just" want to create an external contour to the existing one. Imagine that I have the interior, and then I want to create an external at ds distance. https://en.wikipedia.org/wiki/Time_ev...
So you want to create the outbound contour so it will vary in shape? I do not know how to do that, but if you want to just duplicate it and make it a little bigger, then you can just do a new contour that is the same as the resized initial (
for (cv::Point p in contour) { outboundContour.push_back(cv::Point(p.x * ds, p.y * ds)); }
)Yes, that's what i want to do, I don't know how to do either. I think that your code won't work, in particular in the arcs
AA, so you need to create a contour of the contour? Then draw it in a new mat and then apply find contour. But it is strange that you want to have the contours, and the contours of contours... why would you have an arc (contour not closed)?
YesI want to create a contour of the contour. Then I'll fit both in a rectangle box. Both contours will became holes of the rectangle. What I want meant with "arc" was the semi-circle perimeter.
Normally if it is an area, you can detect its contour, and you can do the erosion (if you do not like the my resize thing) on the contour. More you are saying in a comment of your answer that you do not want a contour of a contour...