MATLAB: I have an assignment that requires us to calculate the total forest area against the total area of land given the BMP image

calculating areaimread

I am required to import the images using the imread function, covert it into grayscale and calculate the percentage forest area given the equation:
They specified that:
  • Green (forest) in grayscale = 75 to 115 (inclusive)
  • Light blue (water) in grayscale = 240
  • Black (text) in grayscale = 0
  • All other colours in grayscale represent land
I have imported the images and converted them into grayscale with the following code
yr_1950 = imread('1950.bmp');
yr_1950 = rgb2gray(yr_1950);
yr_1985 = imread('1985.bmp');
yr_1985 = rgb2gray(yr_1985);
yr_2000 = imread('2000.bmp');
yr_2000 = rgb2gray(yr_2000);
yr_2005 = imread('2005.bmp');
yr_2005 = rgb2gray(yr_2005);
yr_2010 = imread('2010.bmp');
yr_2010 = rgb2gray(yr_2010);
yr_2020 = imread('2020.bmp');
yr_2020 = rgb2gray(yr_2020);
This is one of the images provided to me
I am unsure on how to calculate the forest area and total land area with the given information. Any help would be much appreciated.

Best Answer

Learn to code: Please check what the question asked for.
From the following code, you can get the idea, how can you proceed with the problem
im=imread('1950.bmp');
gray_image=rgb2gray(im);
[rows colm]=size(gray_image);
nos_forest=sum(sum(gray_image>75 & gray_image<115));
nos_water=sum(sum(gray_image==240));
nos_text=sum(sum(gray_image==0));
nos_land=rows*colm-(nos_forest+nos_water+nos_text);
fprintf('The Forest Area is %.2f%%',(nos_forest/(rows*colm))*100);
fprintf('\n The Water Area is %.2f%%',(nos_water/(rows*colm))*100);
fprintf('\n The Land Area is %.2f%%',(nos_land/(rows*colm))*100);
Related Question