{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# OpenCV filter\n\nThis demo shows how OpenCV filters are applied to the ``dataObject``.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from itom import dataObject\nfrom itom import algorithms\nfrom itom import plot\nfrom itom import filterHelp\n\n# create a randomly filled 150x150px dataObject\ndObj = dataObject.rand([150, 150], \"float32\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Get information about the filter and its parameters.\nFirst, no idea about the filters name, therefore get all names containing the keyword ``cv``:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "filterInfoDict = filterHelp(\"cv\", dictionary=1)\n\nfor key, value in filterInfoDict.items():\n print(\"{}: {}\".format(value[\"name\"], value[\"description\"]))\n\n# the desired filter is called \"cvMedianBlur\", now obtain detailed information\nmedianBlurDict = filterHelp(\"cvMedianBlur\", dictionary=1)\n\nprint(\"{}: {}\".format(medianBlurDict[\"cvMedianBlur\"][\"name\"], medianBlurDict[\"cvMedianBlur\"][\"description\"]))\n\n# create an empty output image (its content will be filled within the filter-call)\noutputImage = dataObject()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Call the filter. The parameters after the filter name are the\n``mandatory`` parameters followed by the ``optional`` ones (if desired):\n\n1. parameter (mand): input image\n\n2. parameter (mand): output image\n\n3. kernellength (opt): size of squared filter kernel (default: 3)\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "algorithms.cvMedianBlur(dObj, outputImage, 5)\n\nplot(dObj) # plot original image\nplot(outputImage) # plot filtered image" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.10" } }, "nbformat": 4, "nbformat_minor": 0 }