├── Read_Image.m ├── Gray_Image.m ├── Img_Edge.jpg ├── Img_gray.jpg ├── Final_Image.jpg ├── Img_Denoise.jpg ├── Img_Dilate.jpg ├── Img_Entropy.jpg ├── Dilate_New_Img.jpg ├── Expanded_Image.jpg ├── Final_Results.jpg ├── Localization.jpg ├── sonar_original.jpg ├── Removing_Shadow_Boundaries.jpg ├── Dilate_Image.m ├── Edge_Detection.m ├── Denoise.m ├── ISSUE_TEMPLATE ├── feature_request.md └── bug_report.md ├── Cover_Denoise_Image.m ├── postprocessing.m ├── Remove_Shadow_Boundary.m ├── README.md ├── Localization_Ship.m ├── main.m ├── Remove_the_margin_of_Ship.m └── Entropy_Segmentation.m /Read_Image.m: -------------------------------------------------------------------------------- 1 | function Original_Image = Read_Image(Address) 2 | Original_Image = imread(Address); 3 | -------------------------------------------------------------------------------- /Gray_Image.m: -------------------------------------------------------------------------------- 1 | function [Img_gray] = Gray_Image(Original_Image) 2 | Img_gray = rgb2gray(Original_Image); 3 | -------------------------------------------------------------------------------- /Img_Edge.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SuperBruceJia/Sonar-Image-Segmentation-through-Entropy-Method/HEAD/Img_Edge.jpg -------------------------------------------------------------------------------- /Img_gray.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SuperBruceJia/Sonar-Image-Segmentation-through-Entropy-Method/HEAD/Img_gray.jpg -------------------------------------------------------------------------------- /Final_Image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SuperBruceJia/Sonar-Image-Segmentation-through-Entropy-Method/HEAD/Final_Image.jpg -------------------------------------------------------------------------------- /Img_Denoise.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SuperBruceJia/Sonar-Image-Segmentation-through-Entropy-Method/HEAD/Img_Denoise.jpg -------------------------------------------------------------------------------- /Img_Dilate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SuperBruceJia/Sonar-Image-Segmentation-through-Entropy-Method/HEAD/Img_Dilate.jpg -------------------------------------------------------------------------------- /Img_Entropy.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SuperBruceJia/Sonar-Image-Segmentation-through-Entropy-Method/HEAD/Img_Entropy.jpg -------------------------------------------------------------------------------- /Dilate_New_Img.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SuperBruceJia/Sonar-Image-Segmentation-through-Entropy-Method/HEAD/Dilate_New_Img.jpg -------------------------------------------------------------------------------- /Expanded_Image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SuperBruceJia/Sonar-Image-Segmentation-through-Entropy-Method/HEAD/Expanded_Image.jpg -------------------------------------------------------------------------------- /Final_Results.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SuperBruceJia/Sonar-Image-Segmentation-through-Entropy-Method/HEAD/Final_Results.jpg -------------------------------------------------------------------------------- /Localization.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SuperBruceJia/Sonar-Image-Segmentation-through-Entropy-Method/HEAD/Localization.jpg -------------------------------------------------------------------------------- /sonar_original.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SuperBruceJia/Sonar-Image-Segmentation-through-Entropy-Method/HEAD/sonar_original.jpg -------------------------------------------------------------------------------- /Removing_Shadow_Boundaries.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SuperBruceJia/Sonar-Image-Segmentation-through-Entropy-Method/HEAD/Removing_Shadow_Boundaries.jpg -------------------------------------------------------------------------------- /Dilate_Image.m: -------------------------------------------------------------------------------- 1 | function Img_Dilate = Dilate_Image(Dilate_New_Img) 2 | %Dilate "Removing Boundaries" Image ------>Morphological 3 | tool = strel('disk',3); 4 | Img_Dilate = imdilate(Dilate_New_Img, tool); -------------------------------------------------------------------------------- /Edge_Detection.m: -------------------------------------------------------------------------------- 1 | function Img_Edge = Edge_Detection(Img_Denoise) 2 | %Edge Detection: Roberts Operator 3 | %Operators: roberts, sobel, log, canny, prewitt 4 | Img_Edge = edge(Img_Denoise, 'roberts'); %G[i,j] = |f[i , j] - f[ i+1, j+1]| + |f[i+1, j] - f[i, j+1]| -------------------------------------------------------------------------------- /Denoise.m: -------------------------------------------------------------------------------- 1 | function Img_Denoise = Denoise(Img_gray) 2 | %Denoise: DCT (Discrete Cosine Transform) 3 | %medfilt2, Lee, Kuan, Frost, wavelets 4 | [m, n] = size(Img_gray); 5 | Img_Denoise = dct2(Img_gray); %Discrete Cosine Transform : Noise --> High Frequency --> Low Amplitude 6 | I = zeros(m, n); 7 | I(1:m/3, 1:n/3) = 1; %Keep Low Frequency Denoise High Frequency 8 | Ydct = Img_Denoise .* I; %Denoise 9 | Img_Denoise = uint8(idct2(Ydct)); %Inverse Discrete Cosine Transform 10 | -------------------------------------------------------------------------------- /ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Version [e.g. 22] 29 | 30 | **Additional context** 31 | Add any other context about the problem here. 32 | -------------------------------------------------------------------------------- /Cover_Denoise_Image.m: -------------------------------------------------------------------------------- 1 | function Expanded_Image = Cover_Denoise_Image(Img_Dilate, Img_Denoise, Removing_Shadow_Boundaries) 2 | %Cover Denoise Original Image 3 | [Localization, yuzhi1, yuzhi2, lyuzhi1, lyuzhi2] = Localization_Ship(Removing_Shadow_Boundaries); 4 | Expanding_Image = Img_Dilate; %Expanding Image ------> Smaller Image 5 | Expanded_Image = Img_Denoise; %Expanded Image ------> Bigger Image 6 | [height, width] = size(Expanded_Image); 7 | 8 | for line_Expanded_Image = 1:height 9 | for column_Expanded_Image = 1:width 10 | for line_Image_Expanding = (yuzhi1+line_Expanded_Image): yuzhi2 11 | for column_Image_Expanding = (lyuzhi1+column_Expanded_Image): lyuzhi2 12 | if Expanding_Image(line_Expanded_Image, column_Expanded_Image) == 1 13 | Expanded_Image(yuzhi1+line_Expanded_Image, lyuzhi1+column_Expanded_Image) = 255; 14 | end 15 | end 16 | end 17 | end 18 | end -------------------------------------------------------------------------------- /postprocessing.m: -------------------------------------------------------------------------------- 1 | function Final_Image = postprocessing(Img_Entropy) 2 | %Filling the Entropy Segmentation Image: Finding the First White and the First Black Pixel Then Merge White Color 3 | [m, n] = size(Img_Entropy); 4 | Img_Entropy1=zeros(m,n); 5 | Final_Image=Img_Entropy; 6 | for i=1:m 7 | for j=1:n 8 | if Img_Entropy(i,j)==255 9 | Img_Entropy1(i,j)=1; 10 | break; 11 | end 12 | end 13 | end 14 | for i=1:m 15 | for j=1:n 16 | if Img_Entropy(i,j)==0 17 | Img_Entropy1(i,j)=1; 18 | break; 19 | end 20 | end 21 | end 22 | 23 | for i=1:m 24 | he=0; 25 | he1=0; 26 | for j=1:n 27 | he=he+Img_Entropy1(i,j); 28 | if he==2 %line with white and black 29 | for h=1:n 30 | he1=he1+Img_Entropy1(i,h); 31 | if he1==1 %first white 32 | Final_Image(i,h)=255; 33 | elseif he1==2 %first black 34 | break; 35 | end 36 | end 37 | end 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /Remove_Shadow_Boundary.m: -------------------------------------------------------------------------------- 1 | function Removing_Shadow_Boundaries = Remove_Shadow_Boundary(Img_Edge, Img_Denoise) 2 | %Removing Shadow Boundaries 3 | [m, n] = size(Img_Edge); 4 | Extend_four = ones(m, n+16); 5 | Extend_four_2 = ones(m, n+16); 6 | for i = 1:m 7 | for j = 1:7 8 | Extend_four(i, j) = 150; 9 | Extend_four_2(i,j) = 150; 10 | end 11 | end 12 | for i = 1:m 13 | for j = n+8:n+16 14 | Extend_four(i, j) = 150; 15 | Extend_four_2(i, j) = 150; 16 | end 17 | end 18 | for i = 1:m 19 | for j = 1:n 20 | Extend_four(i, j+7) = Img_Denoise(i, j); 21 | Extend_four_2(i, j+7) = Img_Edge(i, j); 22 | end 23 | end 24 | jiegou = Extend_four_2; 25 | jie2gou = Extend_four_2; 26 | for i = 1:m 27 | for j = 8:n+8 28 | if Extend_four_2(i, j) == 1 29 | jiegou(i,j)=floor((Extend_four(i,j-7)+Extend_four(i,j-6)+Extend_four(i,j-5)+... 30 | Extend_four(i,j-4)+Extend_four(i,j-3)+Extend_four(i,j-2)+Extend_four(i,j-1))/9); 31 | jie2gou(i,j)=floor((Extend_four(i,j+7)+Extend_four(i,j+6)+Extend_four(i,j+5)+... 32 | Extend_four(i,j+4)+Extend_four(i,j+3)+Extend_four(i,j+2)+Extend_four(i,j+1))/7); 33 | end 34 | end 35 | end 36 | jiegou = uint8(jiegou); 37 | jie2gou = uint8(jie2gou); 38 | % figure(5) 39 | % imshow(jiegou), title('jiegou') 40 | jiegou1 = jiegou; 41 | for i = 1:m 42 | for j = 1:n+8 43 | if jiegou(i, j) <= 80 && jie2gou(i, j) > 50 && jie2gou(i, j) < 150 44 | jiegou1(i, j) = 0; 45 | end 46 | end 47 | end 48 | % figure(6) 49 | % imshow(jiegou1), title('jiegou1') 50 | 51 | Removing_Shadow_Boundaries = jiegou1(: ,8:n+7); 52 | t = graythresh(Removing_Shadow_Boundaries); 53 | Removing_Shadow_Boundaries = im2bw(Removing_Shadow_Boundaries, t); 54 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sonar Image Segmentation via Entropy Method 2 | 3 | Author: Shuyue Jia and Ziyu Huo @ Human Sensor Laboratory, School of Automation Engineering, Northeast Electric Power University, Jilin, China. 4 | 5 | Date: June of 2018 6 | 7 | # 🎉 News 8 | [2020] ![](figures/news.gif) A [𝗣𝗮𝘁𝗲𝗻𝘁](https://patents.google.com/patent/CN112164079A/en) is published based on this project and repo codes. 9 | 10 | # Read the Original Shipwrecked Sonar Image 11 | 12 | ![](https://github.com/SuperBruceJia/Sonar-Image-Segmentation-through-Entropy-Method/raw/master/sonar_original.jpg) 13 | 14 | # Gray the Image 15 | 16 | ![](https://github.com/SuperBruceJia/Sonar-Image-Segmentation-through-Entropy-Method/raw/master/Img_gray.jpg) 17 | 18 | # Denoise the Image: DCT (Discrete Cosine Transform) Denoise 19 | 20 | ![](https://github.com/SuperBruceJia/Sonar-Image-Segmentation-through-Entropy-Method/raw/master/Img_Denoise.jpg) 21 | 22 | # Edge Detection (Roberts Operator) 23 | 24 | ![](https://github.com/SuperBruceJia/Sonar-Image-Segmentation-through-Entropy-Method/raw/master/Img_Edge.jpg) 25 | 26 | # Removing Shadow Boundaries 27 | 28 | ![](https://github.com/SuperBruceJia/Sonar-Image-Segmentation-through-Entropy-Method/raw/master/Removing_Shadow_Boundaries.jpg) 29 | 30 | # Image Localization (Threshold) 31 | 32 | ![](https://github.com/SuperBruceJia/Sonar-Image-Segmentation-through-Entropy-Method/raw/master/Localization.jpg) 33 | 34 | # Remove Ship Boundaries 35 | 36 | ![](https://github.com/SuperBruceJia/Sonar-Image-Segmentation-through-Entropy-Method/raw/master/Dilate_New_Img.jpg) 37 | 38 | # Image Dilate White Pixel (Morphology Dilation) 39 | 40 | ![](https://github.com/SuperBruceJia/Sonar-Image-Segmentation-through-Entropy-Method/raw/master/Img_Dilate.jpg) 41 | 42 | # Merge Denoise & Dilation Images 43 | 44 | ![](https://github.com/SuperBruceJia/Sonar-Image-Segmentation-through-Entropy-Method/raw/master/Expanded_Image.jpg) 45 | 46 | # 2-D Entropy Segamentation 47 | 48 | ![](https://github.com/SuperBruceJia/Sonar-Image-Segmentation-through-Entropy-Method/raw/master/Img_Entropy.jpg) 49 | 50 | # Postprocessing 51 | 52 | ![](https://github.com/SuperBruceJia/Sonar-Image-Segmentation-through-Entropy-Method/raw/master/Final_Image.jpg) 53 | -------------------------------------------------------------------------------- /Localization_Ship.m: -------------------------------------------------------------------------------- 1 | function [Localization, yuzhi1, yuzhi2, lyuzhi1, lyuzhi2] = Localization_Ship(Removing_Shadow_Boundaries) 2 | % Localization Ship 3 | %Find Line Location 4 | [m, n]=size(Removing_Shadow_Boundaries); 5 | A = []; 6 | for i = 1:m 7 | for j = 1:n 8 | num_white = sum(Removing_Shadow_Boundaries(i, :)); 9 | A(i) = num_white; 10 | end 11 | end 12 | A = A./sum(A); 13 | x_axis = 1:1:m; 14 | y_axis = A; 15 | % figure(1) 16 | % bar(x_axis, y_axis) 17 | B = medfilt1(A,10); 18 | B = medfilt1(B,10); 19 | y_axis2 = B; 20 | % figure(2) 21 | % bar(x_axis, y_axis2) 22 | Hzy1=zeros(1,m+4); 23 | Hzy1(3:m+2)=y_axis2; 24 | hzyx(1:m+4)=1:1:m+4; 25 | % figure(3) 26 | % bar(hzyx, Hzy1) 27 | Hzy2=Hzy1; 28 | tt=0; 29 | for i=3:m+2 30 | Hzy2(i)=(Hzy1(i-2)+Hzy1(i-1)+Hzy1(i)+Hzy1(i+1)+Hzy1(i+2))/5; 31 | if Hzy2(i)>tt 32 | tt=Hzy2(i); 33 | tt1=i; 34 | end 35 | end 36 | % figure(4) 37 | % bar(hzyx, Hzy2) 38 | tt2=10; 39 | tt3=10; 40 | for i=3:m+2 41 | if Hzy2(i)<=tt2 && itt1 46 | tt3=Hzy2(i); 47 | yuzhi2=i; 48 | end 49 | end 50 | 51 | % Find Column Location 52 | [m, n]=size(Removing_Shadow_Boundaries); 53 | A = []; 54 | for i = 1:n 55 | for j = 1:m 56 | num_white = sum(Removing_Shadow_Boundaries(:, i)); 57 | end 58 | A(i) = num_white; 59 | end 60 | A = A./sum(A); 61 | % x_axis = 1:1:n; 62 | % y_axis = A; 63 | % bar(x_axis, y_axis) 64 | B = medfilt1(A,10); 65 | B = medfilt1(B,10); 66 | B = medfilt1(B,10); 67 | B = medfilt1(B,10); 68 | y_axis2 = B; 69 | % figure(2) 70 | % bar(x_axis, y_axis2) 71 | Hzy1=zeros(1,n+4); 72 | Hzy1(3:n+2)=y_axis2; 73 | hzyx(1:n+4)=1:1:n+4; 74 | % figure(3) 75 | % bar(hzyx, Hzy1) 76 | Hzy2=Hzy1; 77 | tt=0; 78 | for i=3:m+2 79 | Hzy2(i)=(Hzy1(i-2)+Hzy1(i-1)+Hzy1(i)+Hzy1(i+1)+Hzy1(i+2))/5; 80 | if Hzy2(i)>tt 81 | tt=Hzy2(i); 82 | tt1=i; 83 | end 84 | end 85 | % figure(4) 86 | % bar(hzyx, Hzy2) 87 | tt2=10; 88 | tt3=10; 89 | for i=3:m+2 90 | if Hzy2(i)<=tt2 && itt1 95 | tt3=Hzy2(i); 96 | lyuzhi2=i; 97 | end 98 | end 99 | 100 | %Localization Ship 101 | Localization=Removing_Shadow_Boundaries(yuzhi1:yuzhi2, lyuzhi1:lyuzhi2); -------------------------------------------------------------------------------- /main.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear all 3 | 4 | %Read the Original Image 5 | Original_Image = Read_Image('sonar_original.jpg'); 6 | 7 | %Gray the Image 8 | Img_gray = Gray_Image(Original_Image); 9 | 10 | %Denoise the Image 11 | Img_Denoise = Denoise(Img_gray); 12 | 13 | %Edge the Image 14 | Img_Edge = Edge_Detection(Img_Denoise); 15 | 16 | %Removing Shadow Boundaries 17 | Removing_Shadow_Boundaries = Remove_Shadow_Boundary(Img_Edge, Img_Denoise); 18 | 19 | %Locate the Ship Body 20 | [Localization, yuzhi1, yuzhi2, lyuzhi1, lyuzhi2] = Localization_Ship(Removing_Shadow_Boundaries); 21 | 22 | %Remove the margin of Ship 23 | [Dilate_New_Img, jg_recreate] = Remove_the_margin_of_Ship (Localization); 24 | 25 | %Dilate the Image 26 | Img_Dilate = Dilate_Image(Dilate_New_Img); 27 | 28 | %Cover the Denoise Image With Dilation Image 29 | Expanded_Image = Cover_Denoise_Image(Img_Dilate, Img_Denoise, Removing_Shadow_Boundaries); 30 | 31 | % 2-Dimensionality Entropy Segmentation ------> Expanding Image 32 | Img_Entropy = Entropy_Segmentation(Expanded_Image); 33 | 34 | %Filling the Entropy Segmentation Image: Finding the First White and the First Black Pixel Then Merge White Color 35 | Final_Image = postprocessing(Img_Entropy); 36 | 37 | 38 | 39 | %Draw Result 40 | figure(1) 41 | subplot(3, 4, 1), imshow(Original_Image), title('Original Image') 42 | subplot(3, 4, 2), imshow(Img_gray), title('Gray Image') 43 | subplot(3, 4, 3), imshow(Img_Denoise), title('Denoise Image (Discrete Cosine Transform)') 44 | subplot(3, 4, 4), imshow(Img_Edge), title('Edge Image (Roberts)') 45 | subplot(3, 4, 5), imshow(Removing_Shadow_Boundaries), title('Remove Shadow Boundaries') 46 | subplot(3, 4, 6), imshow(Localization), title('Ship Localization (Threshold)') 47 | subplot(3, 4, 7), imshow(jg_recreate), title('Ship Boundaries Extraction (Left & Right Pixel)') 48 | subplot(3, 4, 8), imshow(Dilate_New_Img), title('Remove Ship Boundaries') 49 | subplot(3, 4, 9), imshow(Img_Dilate), title('Dilate White Pixel (Morphology Dilation)') 50 | subplot(3, 4, 10), imshow(Expanded_Image), title('Merge Denoise & Dilation Images') 51 | subplot(3, 4, 11), imshow(Img_Entropy), title('2-D Entropy Segamentation') 52 | subplot(3, 4, 12), imshow(Final_Image), title('Postprocessing') 53 | 54 | % imwrite(Img_gray, 'Img_gray.jpg') 55 | % imwrite(Img_Denoise, 'Img_Denoise.jpg') 56 | % imwrite(Img_Edge, 'Img_Edge.jpg') 57 | % imwrite(Removing_Shadow_Boundaries, 'Removing_Shadow_Boundaries.jpg') 58 | % imwrite(Localization, 'Localization.jpg') 59 | % imwrite(Dilate_New_Img, 'Dilate_New_Img.jpg') 60 | % imwrite(Img_Dilate, 'Img_Dilate.jpg') 61 | % imwrite(Expanded_Image, 'Expanded_Image.jpg') 62 | % imwrite(Img_Entropy, 'Img_Entropy.jpg') 63 | % imwrite(Final_Image, 'Final_Image.jpg') 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /Remove_the_margin_of_Ship.m: -------------------------------------------------------------------------------- 1 | function [Dilate_New_Img, jg_recreate] = Remove_the_margin_of_Ship (Localization) 2 | %Removing the margin of Ship 3 | [m1, n1] = size(Localization); 4 | white_pixel = 1; 5 | first_location = []; 6 | last_location = []; 7 | jg = Localization; 8 | jg_new = uint8(Localization); 9 | 10 | %Find the first and Last White Pixel and Save the Index 11 | for i = 1:m1 12 | for j = 1:n1 13 | if jg(i, j) == 0 14 | random_pixel = randi(224)+1; 15 | jg_new(i, j) = random_pixel; 16 | end 17 | pixel_line = uint8(jg_new(i, :)); 18 | [white_pixel ,index_first] = unique (pixel_line); %Find the First White Pixel Using unique() 19 | [white_pixel, index_last] = unique (pixel_line, 'legacy'); %Find the Last White Pixel using unique( ***,'legacy' ) 20 | first_location(i) = index_first(1); 21 | last_location(i) = index_last(1); 22 | end 23 | end 24 | 25 | first_coordinate = []; 26 | last_coordinate = []; 27 | line = 1:1:m1; 28 | first_coordinate = [line', first_location']; %Save the First Index 29 | last_coordinate = [line', last_location']; %Save the Last Index 30 | 31 | %Margin of Ship 32 | jg_recreate = jg; 33 | for i = 1:m1 34 | for j = 1:n1 35 | if jg_recreate(i, j) ~= 0 36 | jg_recreate(i, j) = 0; 37 | end 38 | jg_recreate(first_coordinate(i, 1), first_coordinate(i, 2)) = 1; %Highlight the First Side (Left) White Margin 39 | jg_recreate(last_coordinate(i, 1), last_coordinate(i, 2)) = 1; %Highlight the Last Side (Right) White Margin 40 | end 41 | end 42 | 43 | %Removing Margin of Ship ------> Change the Cycle 8 pixels into Black (0) 44 | Dilate_New_Img = jg; 45 | for i = 1:m1 46 | Dilate_New_Img(first_coordinate(i, 1), first_coordinate(i, 2)) = 0; 47 | Dilate_New_Img(first_coordinate(i, 1)+1, first_coordinate(i, 2)) = 0; 48 | Dilate_New_Img(first_coordinate(i, 1), first_coordinate(i, 2)+1) = 0; 49 | Dilate_New_Img(first_coordinate(i, 1)+1, first_coordinate(i, 2)+1) = 0; 50 | 51 | Dilate_New_Img(last_coordinate(i, 1), last_coordinate(i, 2)) = 0; 52 | Dilate_New_Img(last_coordinate(i, 1)+1, last_coordinate(i, 2)) = 0; 53 | Dilate_New_Img(last_coordinate(i, 1), last_coordinate(i, 2)+1) = 0; 54 | Dilate_New_Img(last_coordinate(i, 1)+1, last_coordinate(i, 2)+1) = 0; 55 | 56 | if i > 1 57 | Dilate_New_Img(first_coordinate(i, 1)-1, first_coordinate(i, 2)) = 0; 58 | Dilate_New_Img(last_coordinate(i, 1)-1, last_coordinate(i, 2)) = 0; 59 | 60 | if first_coordinate(i, 2) > 1 61 | Dilate_New_Img(first_coordinate(i, 1), first_coordinate(i, 2)-1) = 0; 62 | Dilate_New_Img(first_coordinate(i, 1)-1, first_coordinate(i, 2)-1) = 0; 63 | end 64 | 65 | if last_coordinate(i, 2) > 1 66 | Dilate_New_Img(last_coordinate(i, 1), last_coordinate(i, 2)-1) = 0; 67 | Dilate_New_Img(last_coordinate(i, 1)-1, last_coordinate(i, 2)-1) = 0; 68 | end 69 | end 70 | end 71 | -------------------------------------------------------------------------------- /Entropy_Segmentation.m: -------------------------------------------------------------------------------- 1 | function Img_Entropy = Entropy_Segmentation(Expanded_Image) 2 | % 2-Dimensionality Entropy Segmentation ------> Expanding Image 3 | a = Expanded_Image; %ES Input Image 4 | a0=double(a); 5 | [m,n]=size(a); 6 | h=1; 7 | a1=zeros(m,n); 8 | 9 | for i=1:m 10 | for j=1:n 11 | r=0; 12 | for k=-h:h 13 | for w=-h:h 14 | r=r+1; 15 | p=i+k; 16 | q=j+w; 17 | if (p<=0)||( p>m) 18 | p=i; 19 | end 20 | if (q<=0)||(q>n) 21 | q=j; 22 | end 23 | a1(i,j)=a0(p,q)+a1(i,j); 24 | C(r)=a0(p,q) ; 25 | end 26 | end 27 | 28 | a2(i,j)=uint8(1/9*a1(i,j)); 29 | %a2(i,j)= mode(C); 30 | end 31 | end 32 | fxy=zeros(256,256); 33 | 34 | for i=1:m 35 | for j=1:n 36 | c1=a0(i,j); 37 | d=double(a2(i,j)); 38 | fxy(c1+1,d+1)=fxy(c1+1,d+1)+1; 39 | end 40 | end 41 | Pxy=fxy/m/n; 42 | D = padarray(Pxy,[1 1],0,'both'); 43 | [mm,nn]=size(D); 44 | for i=2:mm-1 45 | for j=2:nn-1 46 | h(i-1,j-1)=D(i-1,j-1)+D(i-1,j)+D(i-1,j+1)+D(i,j-1)+D(i,j)+D(i,j+1)+D(i+1,j-1)+D(i+1,j)+D(i+1,j+1); 47 | w(i-1,j-1)=1-h(i-1,j-1)-abs(i-1-j-1)/100; 48 | end 49 | end 50 | 51 | av1=0; 52 | av2=0; 53 | av3=0; 54 | ab=0.5; 55 | pth=0; 56 | pth1=0; 57 | p=zeros(234,216); 58 | p1=zeros(234,216); 59 | aav1=zeros(234,216); 60 | aaav3=zeros(234,216); 61 | 62 | for i=4:237 63 | for j=4:219 64 | pth=pth+Pxy(i,j); 65 | p(i,j)=pth; 66 | end 67 | end 68 | 69 | for i=4:237 70 | for j=4:219 71 | p1(i,j)=1-p(i,j); 72 | end 73 | end 74 | 75 | for i=5:237 76 | for j=5:219 77 | av1= av1+(Pxy (i,j)^ab); 78 | aav1(i,j)=av1; 79 | end 80 | end 81 | 82 | for i=5:230 83 | for j=5:210 84 | aaav3(i,j)=aav1(230,210)-aav1(i,j); 85 | end 86 | end 87 | 88 | b=0; 89 | b1=0; 90 | tt=0; 91 | ss=0; 92 | tt1=0; 93 | ss1=0; 94 | 95 | for s=70:100 96 | for t=70:100 97 | for s1=100:150 98 | for t1=100:150 99 | aa1=1/(ab-1)*(1-aav1(s,t)/(p(s,t)^ab)); 100 | aa2=1/(ab-1)*(1-(aav1(s1,t1)-aav1(s,t))/((p(s1,t1)-p(s,t))^ab)); 101 | aa3=1/(ab-1)*(1-aaav3(s1,t1)/(p1(s1,t1)^ab)); 102 | E=(aa1+aa2+aa3)+w(s,t)+w(s1,t1); 103 | if E>b 104 | b=E; 105 | ss=s; 106 | tt=t; 107 | ss1=s1; 108 | tt1=t1; 109 | else 110 | b=b; 111 | ss=ss; 112 | tt=tt; 113 | ss1=ss1; 114 | tt1=tt1; 115 | end 116 | end 117 | end 118 | end 119 | end 120 | 121 | if sstt1 130 | turn2=ss1; 131 | else 132 | turn2=tt1; 133 | end 134 | ss1=turn2; 135 | tt1=turn2; 136 | 137 | I1=zeros(m,n); 138 | for i=1:m 139 | for j=1:n 140 | if a0(i,j)>=ss1+50&&a2(i,j)>=tt1+50 141 | I1(i,j)=255; 142 | elseif a0(i,j)<=ss-50 && a2(i,j)<=tt -50 143 | I1(i,j)=0; 144 | else 145 | I1(i,j)=100; 146 | end 147 | end 148 | end 149 | 150 | ss; 151 | tt; 152 | ss1; 153 | tt1; 154 | Img_Entropy = uint8(I1); --------------------------------------------------------------------------------