how to code the following program in MATLAB 2010

2 views (last 30 days)
Open a gray scale image file
store image height to m and width to n, respectively
declare two 2-D Matrices, namely, matrix[m][n], matrix1[m][n]
declare integer, a1=0, a2=0, a3=0, a4=0, a5=0
read pixel one by one until end of file
for(int i=0; i<m;++i)
{
for(int j=0;j<n;++j)
{
matrix[i][j] = bi.getRGB(i,j);
matrix1[i][j] = bi.getRGB(i,j);
}
}
for(int r = 1; r < m-1; r++)
{
for(int c = 1; c < n-1; c++)
{
if((((matrix[r-1][c] == a1 ) && (matrix[r][c-1] == a2 ))
&& ((matrix[r-1][c] == a4) && (matrix[r][c+1] == a2 )))
&& (((matrix[r+1][c] == a4) && (matrix[r][c-1] == a2 ))
&& ((matrix[r+1][c] == a4) && (matrix[r][c+1] == a2 )))
&& (matrix[r][c] == a5))
matrix1[r][c] = 255;
}
}
write matrix1[m][n] to another image file
In this algorithm, each and every pixel is checked with its neighbor pixels. If all neighbors are black or 0 then make the pixel white or 255. We can say the concern pixel will die.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!