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:

25 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