Crop elliptical region from image

We know that we can represent image as a matrix, and matrix can not be elliptical. So when you want to crop a elliptical area from an image, then you have to extract the elliptical region and remove rest of the information outside the ellipse. This can be done by AND operation of the image with an elliptical mask.

Steps:
  1. Read the image and convert to gray scale.
  2. Create the elliptical mask. ( use Negative argument to fill the ellipse)
    ellipse( im2, Point( 120, 130 ), Size( 50.0, 60.0 ), 0, 0, 360, Scalar( 255, 255, 255), -1, 8 );
  3. Use AND operation.
  4. Show the result.

Functions:

Example:

-------------
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include<conio.h>


using namespace cv;
using namespace std;

int main()
{
    Mat im1 = imread("Lena.jpg");
    if (im1.empty()) 
    {
        cout << "Cannot load image!" << endl;
        return -1;
    }
 cvtColor(im1, im1, CV_BGR2GRAY);
    imshow("im1", im1);  // Origina image
 
 Mat im2(im1.rows, im1.cols, CV_8UC1, Scalar(0,0,0));
 ellipse( im2, Point( 120, 130 ), Size( 50.0, 60.0 ), 0, 0, 360, Scalar( 255, 255, 255), -1, 8 );
 imshow("im2",im2);  // mask
 
 Mat res;
 bitwise_and(im1,im2,res);     
 imshow("AND",res);  // resultant image

    waitKey(0);
 return 0;
}
-------------
Result:

48 comments:

  1. Hey, great tutorials. Just to add a complement: If you wish to do the same on a 3 channel (color) image, you have to split it first, perform AND on each channel, then merge it. You've got to make a vector to split it into. Cheers!

    ReplyDelete
    Replies
    1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from Javascript Training in Chennai . or learn thru JavaScript Online Training in India. Nowadays JavaScript has tons of job opportunities on various vertical industry. JavaScript Training in Chennai

      Delete
  2. Does someone know anything about detection with eigenface method
    I need help

    ReplyDelete
  3. Trung tâm dạy kế toán thực tế Tại cầu giấy
    Trung tâm dạy kế toán thực tế Tại từ liêm
    Trung tâm dạy kế toán thực tế Tại thanh xuân
    Trung tâm dạy kế toán thực tế Tại hà đông
    Trung tâm dạy kế toán thực tế Tại long biên
    Trung tâm dạy kế toán thực tế Tại nguyễn chính thanh đống đa
    Trung tâm dạy kế toán thực tế Tại minh khai hai bà trưng
    Trung tâm dạy kế toán thực tế Tại bắc ninh
    Trung tâm dạy kế toán thực tế Tại hải phòng
    Trung tâm dạy kế toán thực tế Tại tphcm
    Trung tâm dạy kế toán thực tế Tại quận 3
    Trung tâm dạy kế toán thực tế Tại thủ đức
    Trung tâm dạy kế toán thực tế Tại đà nẵng
    Trung tâm dạy kế toán thực tế Tại biên hòa
    Trung tâm dạy kế toán thực tế Tại đồng nai
    Trung tâm dạy kế toán thực tế Tại nam định
    Trung tâm dạy kế toán thực tế Tại thái bình
    Trung tâm dạy kế toán thực tế Tại bắc giang
    Trung tâm dạy kế toán thực tế Tại vĩnh phúc
    Trung tâm dạy kế toán thực tế Tại thái nguyên
    Trung tâm dạy kế toán thực tế Tại quảng ninh
    Trung tâm dạy kế toán thực tế Tại hải dương
    Trung tâm dạy kế toán thực tế Tại hưng yên
    Trung tâm dạy kế toán thực tế Tại hà nam
    Trung tâm dạy kế toán thực tế Tại ninh bình
    Trung tâm dạy kế toán thực tế Tại nghệ an
    Trung tâm dạy kế toán thực tế Tại vũng tàu

    ReplyDelete
  4. Thanks for this informative article, I hope you will get most positive response specially for this post. . . .
    โกเด้นสล็อต

    ReplyDelete
  5. Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include. erba luigia

    ReplyDelete
  6. I just want to tell you that I’m all new to blogging and site-building and really loved your web page. Very likely I’m want to bookmark your site . You amazingly have remarkable posts. Thanks a bunch for sharing your blog.
    Regards - www.office.com/setup
    www.office.com/setup

    ReplyDelete
  7. Thanks for this helpful Blog.
    I used a WordPress plugin that I found interesting. So I would like to recommend it.
    The plugin helps me quickly create and customize images before inserting them in my blog post.
    Check at: https://getpikiz.com/wordpress-plugin/
    It’s free.

    ReplyDelete
  8. Thanks for this helpful Blog.
    I used a WordPress plugin that I found interesting. So I would like to recommend it.
    The plugin helps me quickly create and customize images before inserting them in my blog post.
    Check at: https://getpikiz.com/wordpress-plugin/
    It’s free.

    ReplyDelete
  9. Thanks for this helpful Blog.
    I used a WordPress plugin that I found interesting. So I would like to recommend it.
    The plugin helps me quickly create and customize images before inserting them in my blog post.
    Check at: https://getpikiz.com/wordpress-plugin/
    It’s free.

    ReplyDelete
  10. Thanks for this helpful Blog.
    I used a WordPress plugin that I found interesting. So I would like to recommend it.
    The plugin helps me quickly create and customize images before inserting them in my blog post.
    Check at: https://getpikiz.com/wordpress-plugin/
    It’s free.

    ReplyDelete
  11. Install Office Setup – Sign-in to you microsoft account and then Enter 25 digit alphanumeric office setup product key on country and language.click on next to start office installation.We are the best Office Setup in US, Canada and Australia. At Office Setup, we put high effort, moderate IT answers for organization's, and people.Whether set up or beginning, equipment or programming, system or electronic, we have something for each financial plan. officeplus.net is the exchanging name of Spacesolutions Pvt Ltd situated in California, USA. We are not Microsoft. However we are trained professionals to provide technical support for We are the world's biggest innovation wholesaler and a main innovation deals, showcasing and logistics organization for the IT business around the world. Our people group based ethos, focused costs and nature of administration settles on Office Setup the right decision for your IT needs .Whether you are a learner or experienced in IT our courses are altered to furnish you with the key achievement criteria to thrive in future attempts.
    www.office.com/setup

    ReplyDelete
  12. Install Office Setup – Sign-in to you microsoft account and then Enter 25 digit alphanumeric office setup product key on country and language.click on next to start office installation.We are the best Office Setup in US, Canada and Australia. www.office.com/setup

    ReplyDelete

  13. I love this post.


    โปรโมชั่นGclub ของทางทีมงานตอนนี้แจกฟรีโบนัส 50%
    เพียงแค่คุณสมัคร Gclub กับทางทีมงานของเราเพียงเท่านั้น
    ร่วมมาเป็นส่วนหนึ่งกับเว็บไซต์คาสิโนออนไลน์ของเราได้เลยค่ะ
    สมัครสล็อตออนไลน์ >>> goldenslot
    สนใจร่วมลงทุนกับเรา สมัครเอเย่น Gclub คลิ๊กได้เลย

    ReplyDelete
  14. I love this post.

    เว็บไซต์คาสิโนออนไลน์ที่ได้คุณภาพอับดับ 1 ของประเทศ
    เป็นเว็บไซต์การพนันออนไลน์ที่มีคนมา สมัคร Gclub Royal1688
    และยังมีหวยให้คุณได้เล่น สมัครหวยออนไลน์ ได้เลย
    สมัครสมาชิกที่นี่ >>> Gclub Royal1688
    ร่วมลงทุนสมัครเอเย่นคาสิโนกับทีมงานของเราได้เลย

    ReplyDelete
  15. An amazing web journal I visit this blog, it's unbelievably wonderful. Oddly, in this blog's content made without a doubt and reasonable. The substance of data is informative.
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  16. We produce the Buy Custom Term Papers services as we have an array of writing services in our firm for meeting other requirements. Our Essay Writing Services for sale are affordable to our clients.

    ReplyDelete
  17. Halo,I'm Helena Julio from Ecuador,I want to talk good about Le_Meridian Funding Investors on this topic.Le_Meridian Funding Investors gives me financial support when all bank in my city turned down my request to grant me a loan of 500,000.00 USD, I tried all i could to get a loan from my banks here in Ecuador but they all turned me down because my credit was low but with god grace I came to know about Le_Meridian so I decided to give a try to apply for the loan. with God willing they grant me  loan of 500,000.00 USD the loan request that my banks here in Ecuador has turned me down for, it was really awesome doing business with them and my business is going well now. Here is Le_Meridian Funding Investment Email/WhatsApp Contact if you wish to apply loan from them.Email:lfdsloans@lemeridianfds.com / lfdsloans@outlook.comWhatsApp Contact:+1-989-394-3740.

    ReplyDelete
  18. You can share your valuable content, make an online payment and can connect with your friends or family at an ease. But to keep your system protected from the attack or the involvement of the unnecessary foreign agents, you should install Norton Setup Antivirus 360 via www.norton.com/setup in your workstation.

    ReplyDelete
  19. Thanks for sharing this loving post, and pls see’s my post & tell me…
    Office 2013 Professional Free Download Setup for PC, This is an offline installer (www.office.com/setup) of MS Office 2020 for 32 bit and 64 bit. Office 2010 Professional: http://officeoffice-officeoffice.com/

    ReplyDelete
  20. Thanks for sharing this loving post, and pls see’s my post & tell me…
    Office 2013 Professional Free Download Setup for PC, This is an offline installer (www.office.com/setup) of MS Office 2020 for 32 bit and 64 bit. Office 2010 Professional: http://officeoffice-officeoffice.com/

    ReplyDelete
  21. As an Office tech support executive well praised among the customer to help them in resolving their queries related to office setup. As problem or queries can turn up at anytime so you should be ready for it, just visit Office.Com/Setup and download the latest office setup. While doing so if you come across any difficulty then you can make connection with me on the said below link:

    office.com/setup

    ReplyDelete
  22. Microsoft Office Suite of products developed by Microsoft that includes Microsoft Word, Excel, Access, PowerPoint, and Outlook. Get some easy steps for easy downloading, installing, activating, and re-installing the Microsoft Office suite here

    Regards,

    office.com/setup

    ReplyDelete
  23. Why Do errors Appear while Installing Office?
    The office is one of the most important, best and therefore the top-rated Productivity Software within the market. Office.com/Setup
    This just creates an area for a lot of errors and warnings for the software to possess while installing or while running. there's a transparent need for the software to run on a system that doesn't have any fault and has all the dependencies within the system to run office smoothly, in case any of the need isn't met, the software will simply produce a mistake or a warning which will not allow you to continue the method till the error is fixed and removed in order that you'll have smooth and delightful running software with none problem. If the errors were made to be ignored, it could cause data loss later, so these errors and warnings are permanent.

    ReplyDelete
  24. McAfee Antivirus Plus, McAfee Internet Security, McAfee Total Protection and McAfee LiveSafe are great deals for anyone with lots of devices.
    mcafee activate product key | mcafee.com/activate product key | mcafee com activate product key | mcafee activation key | mcafee com activate uk

    ReplyDelete
  25. Thanks for this helpful Blog.
    I used a WordPress plugin that I found interesting. So I would like to recommend it.
    The plugin helps me quickly create and customize images before inserting them in my blog post.
    Check at: https://getpikiz.com/wordpress-plugin/
    It’s free.

    ReplyDelete
  26. for this helpful Blog.
    I used a WordPress plugin that I found interesting. So I would like to recommend it.
    The Thanks plugin helps me quickly create and customize images before inserting them in my blog post.
    Check at: https://getpikiz.com/wordpress-plugin/
    It’s free.

    ReplyDelete
  27. Thanks for this helpful Blog.
    I used a WordPress plugin that I found interesting. So I would like to recommend it.
    The plugin helps me quickly create and customize images before inserting them in my blog post.
    Check at: https://getpikiz.com/wordpress-plugin/
    It’s free.

    ReplyDelete
  28. Thanks for this helpful Blog.
    I used a WordPress plugin that I found interesting. So I would like to recommend it.
    The plugin helps me quickly create and customize images before inserting them in my blog post.
    Check at: https://getpikiz.com/wordpress-plugin/
    It’s free.

    ReplyDelete
  29. Thanks for this helpful Blog.
    I used a WordPress plugin that I found interesting. So I would like to recommend it.
    The plugin helps me quickly create and customize images before inserting them in my blog post.
    Check at: https://getpikiz.com/wordpress-plugin/
    It’s free.

    ReplyDelete
  30. Thanks for this helpful Blog.
    I used a WordPress plugin that I found interesting. So I would like to recommend it.
    The plugin helps me quickly create and customize images before inserting them in my blog post.
    Check at: https://getpikiz.com/wordpress-plugin/
    It’s free.

    ReplyDelete
  31. Thanks for this helpful Blog.
    I used a WordPress plugin that I found interesting. So I would like to recommend it.
    The plugin helps me quickly create and customize images before inserting them in my blog post.
    Check at: https://getpikiz.com/wordpress-plugin/
    It’s free.

    ReplyDelete
  32. Thanks for this helpful Blog.
    I used a WordPress plugin that I found interesting. So I would like to recommend it.
    The plugin helps me quickly create and customize images before inserting them in my blog post.
    Check at: https://getpikiz.com/wordpress-plugin/
    It’s free.

    ReplyDelete
  33. Your post is very helpful and information is reliable. I am satisfied with your post. Thank you so much for sharing this wonderful post. Visit:- advisor for you office.com/setup | office.com/setup | | Norton.com/setup | office.com/setup | log in Telstra Webmail Account

    ReplyDelete