diff --git a/Image Segmentation #1.cpp b/Image Segmentation #1.cpp new file mode 100644 index 0000000..c233756 --- /dev/null +++ b/Image Segmentation #1.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include +using namespace std; +bool isBoundary(int i,int j,int N,int M){ + return i<0 || i>=N || j<0 || j>=M; +} +void solve(int i,int j,vector&image){ + int N = image.size(); + int M = image[0].length(); + for(int a=-1;a<=1;a++){ + for(int b=-1;b<=1;b++){ + if((a==0 && b==0 )||(abs(a)==1 && abs(b)==1)) + continue; + if(!isBoundary(i+a,j+b,N,M) && image[i+a][j+b]=='1'){ + image[i+a][j+b]='0'; + solve(i+a,j+b,image); + } + } + } +} +int main() { + vector image={ + "000110001010", + "111011110001", + "111010010010", + "100000000100" + }; + + int segments = 0; + for(int i=0;i