{"id":25239439,"url":"https://github.com/mr-talhailyas/conditional-random-fields-crf","last_synced_at":"2026-02-09T23:31:43.366Z","repository":{"id":57465271,"uuid":"326826057","full_name":"Mr-TalhaIlyas/Conditional-Random-Fields-CRF","owner":"Mr-TalhaIlyas","description":"Fully Connected Conditional Random Field","archived":false,"fork":false,"pushed_at":"2024-05-24T06:35:16.000Z","size":5180,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-06T15:06:14.049Z","etag":null,"topics":["conditional-random-fields","crf","image-processing","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Mr-TalhaIlyas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-01-04T22:47:31.000Z","updated_at":"2024-05-24T06:35:19.000Z","dependencies_parsed_at":"2022-09-13T13:40:42.807Z","dependency_job_id":null,"html_url":"https://github.com/Mr-TalhaIlyas/Conditional-Random-Fields-CRF","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mr-TalhaIlyas%2FConditional-Random-Fields-CRF","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mr-TalhaIlyas%2FConditional-Random-Fields-CRF/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mr-TalhaIlyas%2FConditional-Random-Fields-CRF/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mr-TalhaIlyas%2FConditional-Random-Fields-CRF/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mr-TalhaIlyas","download_url":"https://codeload.github.com/Mr-TalhaIlyas/Conditional-Random-Fields-CRF/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238346087,"owners_count":19456681,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["conditional-random-fields","crf","image-processing","python"],"created_at":"2025-02-11T18:28:04.836Z","updated_at":"2025-10-26T14:30:44.646Z","avatar_url":"https://github.com/Mr-TalhaIlyas.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) ![PyPI](https://img.shields.io/pypi/v/a) [![Downloads](https://pepy.tech/badge/seg-crf)](https://pepy.tech/project/seg-crf) [![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2FMr-TalhaIlyas%2FConditional-Random-Fields-CRF\u0026count_bg=%2379C83D\u0026title_bg=%23555555\u0026icon=\u0026icon_color=%23E7E7E7\u0026title=hits\u0026edge_flat=false)](https://hits.seeyoufarm.com)\n\n# Fully Connected CRF\n\nThis repo implements CRF as described in Deeplab paper it takes about 0.2 seconds per image. Following image is taken form **DeepLab** paper\n\n![alt text](https://github.com/Mr-TalhaIlyas/Conditional-Random-Fields-CRF/blob/master/screens/img1.png)\n\n## Requirements\n\n```\nPython \u003c= 3.6\npydensecrf  // Recomended to install before hand via conda-forge see below\ncv2\nmatplotlib\ngray2color\n```\n\n## Installation\nvia [PyPi](https://pypi.org/project/seg-crf/) or\n```\n# first install this to avoid any error.\nconda install -c conda-forge pydensecrf\n# then go here\npip install seg-crf\n```\n\nif you get error during installation due to `pydensecrf` then follow this [link](https://github.com/lucasb-eyer/pydensecrf) to resolve it or just type,\n\n```\npip install git+https://github.com/lucasb-eyer/pydensecrf.git\n```\n## Usage\n\n```python\n\nfrom seg_crf import Seg_CRF\n\nimg_path='D:/Anaconda/Image_analysis/cat.png'\nmodel_op_path='D:/Anaconda/Image_analysis/mask.png'\n\ncrf = Seg_CRF(img_path, model_op_path, 2, img_w=1024, img_h=512, clr_op=True, pallet2use ='cityscape')\n\ngray, rgb = crf.start()\nplt.imshow(rgb)\n\n```\nIt takes following inputs.(see dir `sample_data` for sample masks) `gt` are just groundtruths they are not used during caculation\n\n```\n        ⚠ Zero pixels are consdered background\n        img_path : path to an image, \n                        Format [H, W, 3]; values ranging from [0, 255]\n        model_op_path : path model output of the same input image.\n                        Format [H, W]; values ranging from [0, num_of_classes]\n        num_of_classes : number of classes in a dataset e.g. in cityscape has 30 classes\n        clr_op : color the output or not a bool\n        pallet2use : see https://pypi.org/project/gray2color/ for details\n        img_w : for resizing image and mask to same size default is 1024\n        img_h : for resizing image and mask to same size default is 512\n        apperance_kernel : The PairwiseBilateral term in CRF a list of values in order [sxy, srgb, compat]  \n                            default values are [8, 164, 100]\n        spatial_kernel : The PairwiseGaussian term in CRF a list of values in order [sxy, compat]  \n                            default values are [3, 10]\n```\nMore about spatial and apperance kernel below.\n## Why CRF?\n\nCRF’s are used for smoothing the noisy segmentation maps. See image below.\n\n![alt text](https://github.com/Mr-TalhaIlyas/Conditional-Random-Fields-CRF/blob/master/screens/img2.png)\n\n## Types of CRF\n\n### Grid CRF\n\n![alt text](https://github.com/Mr-TalhaIlyas/Conditional-Random-Fields-CRF/blob/master/screens/img4.png)\n\n### Fully connected CRF\nThis is the one implemented in this repo.\n\n![alt text](https://github.com/Mr-TalhaIlyas/Conditional-Random-Fields-CRF/blob/master/screens/img5.png)\n\n## Some mathematical Background\n\nFC CRF consists of two Guassian Kernels one is called appearance kernel and other is called spatioal kernel. The spatial kernel is used of controlling the smoothness of the segmented regions.\nand the appearace kernel controls which regions of segemneted image should be combined to one after lookin at origina input image.\n\n![alt text](https://github.com/Mr-TalhaIlyas/Conditional-Random-Fields-CRF/blob/master/screens/img3.png)\n\n#### You can control the parameters of these kernels as follwoing\n```\n# inside the CRF function and class change;\n#        1. increasing sxy puts more focus on changing intensity\n#        2. if we increase srgb the pixels in close proximity will be assigned one class \n#           (high value will cause the erosion like effect at boundaries)\n```\n## Appearance and Spatial Kernel\n\n```python\n# Default Values are\napperance_kernel = [8, 164, 100] # PairwiseBilateral [sxy, srgb, compat]  \nspatial_kernel = [3, 10]         # PairwiseGaussian  [sxy, compat] \n\n# or if you want to to specify seprately for each XY direction and RGB color channel then\n\napperance_kernel = [(1.5, 1.5), (64, 64, 64), 100] # PairwiseBilateral [sxy, srgb, compat]  \nspatial_kernel = [(0.5, 0.5), 10]                  # PairwiseGaussian  [sxy, compat] \n# Use like\ncrf = Seg_CRF(img_path, model_op_path, 2, img_w=1024, img_h=512,\n                 apperance_kernel=apperance_kernel, spatial_kernel=spatial_kernel,\n                 clr_op=True, pallet2use ='cityscape')\n\ngray, rgb = crf.start()\n```\n## FC-CRF in Machine Learning Pipeling\n\n![alt text](https://github.com/Mr-TalhaIlyas/Conditional-Random-Fields-CRF/blob/master/screens/img6.png)\n\n\n## Visual Results \nFor binar and multiclass segementation\n\n![alt text](https://github.com/Mr-TalhaIlyas/Conditional-Random-Fields-CRF/blob/master/screens/img7.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmr-talhailyas%2Fconditional-random-fields-crf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmr-talhailyas%2Fconditional-random-fields-crf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmr-talhailyas%2Fconditional-random-fields-crf/lists"}