MATLAB exercise program (final corrosion)

Source: Internet
Author: User

The so-called final corrosion does not mean that the image is continuously corroded until it is black. What else does that mean.

Final corrosion means the union of all the remaining parts before the sub-areas disappear in the continuous corrosion process.

There is a connected area:

The final corrosion means that the image is continuously corroded until only the white area in the middle of the ring is left. As follows:

Therefore, after the final corrosion, if the corrosion happens again, the image will be completely lost.

The final corrosive algorithm first uses distance transformation for the original image, and then calculates the maximum value of the region. However, the speed of this method is fast, but I have tried it many times and the results are very unstable.

So I developed an algorithm on my own, which is slow but stable.

1. First mark the connected areas of the original image.

2. The labeled images are continuously corroded. Each corrosion occurs, and the connected areas are re-marked.

3. after each corrosion and marking, check whether any marked area of the image after corrosion disappears. If so, restore the last region that appeared in the region.

4. The program will end until the next corrosion is the same as the result of this corrosion.

The running effect is as follows:

Source image:

Final corrosion:

The Matlab code is as follows:

Clear all; close all1_clc1_img1_imread('te.png '); IMG = img> 128; imshow (IMG); [m n] = size (IMG); imgn = zeros (m, n ); preimg = imgn; Se = strel ('square ', 3); While sum (preimg-IMG ))~ = 0 preimg = IMG; IMG = img> 0; [img label] = liw.g (IMG); % mark different regions, label is the number of regions imgn = imerode (IMG, SE ); % indicates whether any marked area disappears after corrosion hist = zeros (1, label); for I = 1: m for j = 1: n if imgn (I, j) ~ = 0 hist (imgn (I, j) = imgn (I, j); end % count the number of the disappearing region H = []; for I = 1: label if hist (I) = 0 h = [h I]; end % if this region disappears, then restore this region if ~ Isempty (h) L = length (h); for I = 1: m for j = 1: N for k = 1: l if IMG (I, j) = H (k) imgn (I, j) = IMG (I, j); end IMG = imgn; endfigure; imshow (imdilate (imgn> 0, se); % and then expand

With final corrosion and conditional expansion, the implementation of the watershed algorithm is close at hand.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.