how to code the following program in MATLAB 2010a

3 views (last 30 days)
Three separate algorithms are developed, implemented and tested with the following brain tumor MRI image.
These algorithms are:
Algorithm 1: 24-Bit Color Image to 256 Gray Color Image
open 24-bit color image in read mode
store image height to m and width to n, respectively
declare two 2-D Matrices, namely, matrix[m][n], matrix1[m][n]
read pixel one by one until end of file
{
matrix1[i][j] = bi.getRGB(i,j)
b1[i][j]= (bi.getRGB(i,j)) & 0x000000FF
g1[i][j]= (bi.getRGB(i,j) & 0x0000FF00) >> 8
r1[i][j]= (bi.getRGB(i,j) & 0x00FF0000) >> 16
int avg = (r1[i][j]+g1[i][j]+b1[i][j])/3
int newRGB = 0xFF000000 + (avg << 16) + (avg << 8 ) + avg
matrix[i][j] = newRGB
}
write matrix[m][n] to another image file
close all the files
In this algorithm, the 24-bit pixel is separated into 3 bytes. Then the new value is computed and stored in such a way that all the red, green and blue values have been given the perfect weightage for each 24-bit pixel.
Algorithm 2: Image Segmentation Algorithm
open 256 gray color image in read mode
store image height to m and width to n, respectively
declare a 2-D Matrix, matrix[m][n]
read pixel one by one until end of file
{
matrix[i][j] = bi.getRGB(i,j)
if matrix[i][j]<128 then
matrix[i][j] = 0
}
write matrix[m][n] to another image file
close all the files
This algorithm is completely depends on the algorithm A. Here average threshold value is considered, because the grey value is calculated in that way. Here threshold is taken as 128.
Algorithm 3: Edge Detection Algorithm
Open resultant image file from Algorithm B
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.
  1 Comment
Ritu Rana
Ritu Rana on 20 Apr 2015
I know code of Ist algo. Plz help me in Algo 2 & 3 & how to give output of one algo to further algos as these 3 are linked.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!