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:

29 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
  2. Does someone know anything about detection with eigenface method
    I need help

    ReplyDelete
  3. 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

  4. I love this post.


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

    ReplyDelete
  5. 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
  6. 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
  7. 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
  8. 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
  9. This comment has been removed by the author.

    ReplyDelete
  10. I am new visitor of your blog, thank you for sharing this valuable information. I’m looking forward for your upcoming blogs.

    ReplyDelete
  11. Compre documentos en línea, documentos originales y registrados.
    Acerca de Permisodeespana, algunos dicen que somos los solucionadores de problemas, mientras que otros se refieren a nosotros como vendedores de soluciones. Contamos con cientos de clientes satisfechos a nivel mundial. Hacemos documentos falsos autorizados y aprobados como Permiso de Residencia Español, DNI, Pasaporte Español y Licencia de Conducir Española. Somos los fabricantes y proveedores de primer nivel de estos documentos, reconocidos a nivel mundial.

    Comprar permiso de residencia,
    permiso de residenciareal y falso en línea,
    Compre licencia de conducir en línea,
    Compre una licencia de conducir española falsa en línea,
    Comprar tarjeta de identificación,
    Licencia de conducir real y falsa,
    Compre pasaporte real en línea,

    Visit Here fpr more information. :- https://permisodeespana.com/licencia-de-conducir-espanola/
    Address: 56 Guild Street, London, EC4A 3WU (UK)
    Email: contact@permisodeespana.com
    WhatsApp: +443455280186

    ReplyDelete
  12. Thanks for your sharing, I have asked myself how can keep my blog if I have no idea about content? Through your post I have good solutions for this problem.

    ReplyDelete
  13. PLATFORM FOR THE SERVICE DESK WITH ADVANCED FEATURES
    Modern service desks and self-service ticketing are ideal for the healthcare industry, and they have proven to be very successful. Healthcare institutions should implement automated platforms to maximize the benefit of healthcare services for patients, doctors, and administrators.
    Click here: Ai service desk

    ReplyDelete
  14. If you are going for finest contents like me, just go
    to see this website daily for the reason that it presents quality contents, thanks 스포츠중계


    ReplyDelete
  15. This type of clever work and coverage! Keep up the great works guys I’ve incorporated you guys to my own blogroll. Feel free to visit my website;
    야설

    ReplyDelete
  16. You’re making it entertaining and you still care for to keep it smart. I cant wait to read far more from you. That is actually a terrific web site. Feel free to visit my website; 한국야동

    ReplyDelete
  17. I’m confident they will be benefited from this web site. Feel free to visit my website; 국산야동

    ReplyDelete
  18. This type of message always inspiring and I prefer to read quality content, so happy to find good place to many here in the post, the writing is just great, thanks for the post. Feel free to visit my website;
    일본야동

    ReplyDelete
  19. to know more about automated help desk and service desk with rezolve.ai, click down the link here: : https://bit.ly/3MyfJ5Q

    ReplyDelete
  20. Thanks for all the tips mentioned in this article! it's always good to read things you have heard before and are implementing. 바카라사이트

    ReplyDelete
  21. โปร สล็อต pg slot จากเว็บสล็อตออนไลน์ PG-SLOT.GAME ที่ยกเกมสล็อตออนไลน์จากค่ายดังมาอย่างหลากหลายค่ายเกม เช่น pg slot jili joker และอื่นๆอีกมากมายในเว็บเดียว มาแรง 2022

    ReplyDelete
  22. pgslot168 เป็นเกมแบบอย่างที่เล่นได้บนโทรศัพท์เคลื่อนที่สบาย ใช้งานง่าย PG168 มีเกมสล็อตให้เล่นอยู่มากมายเยอะแยะอาทิเช่น สล็อต สามารถใช้เป็นการพนันลงทุนเล่น เว็บไซต์สล็อต

    ReplyDelete
  23. Vrinda Foundation NGO in Mathura - Vrinda Foundation, an impactful NGO in Mathura, is dedicated to community well-being. Join us in our mission for positive change and collective empowerment.

    ReplyDelete
  24. VelementWW, your premier NYC Sign Company, specializes in crafting eye-catching, bespoke signs. Elevate your brand with our innovative designs and quality craftsmanship. Stand out in the bustling cityscape with VelementWW's signage solutions.

    ReplyDelete