0% found this document useful (0 votes)
34 views

Basics: 1. Write A MATLAB Code To Read, Show and Write Image

The document contains MATLAB code examples for basic image processing tasks. It shows how to read, display and write an image, convert an RGB image to grayscale using several methods including pixel-to-pixel conversion, averaging, and an inbuilt MATLAB function, and convert an RGB image to a binary black and white image by thresholding the grayscale pixel values or using an inbuilt MATLAB function. The code is written by Ohm Jodhani for an image processing fundamentals course.

Uploaded by

Darshan
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Basics: 1. Write A MATLAB Code To Read, Show and Write Image

The document contains MATLAB code examples for basic image processing tasks. It shows how to read, display and write an image, convert an RGB image to grayscale using several methods including pixel-to-pixel conversion, averaging, and an inbuilt MATLAB function, and convert an RGB image to a binary black and white image by thresholding the grayscale pixel values or using an inbuilt MATLAB function. The code is written by Ohm Jodhani for an image processing fundamentals course.

Uploaded by

Darshan
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Experiment 0

BASICS
1. Write a MATLAB code to Read, Show and Write Image.
clc;
clear all;
close all;
img = uigetfile('*.jpg','Select Image')
a=imread(img);
imshow(a);
imwrite(a,'ohm.jpg');

2. Write a MATLAB code to convert RGB image to grayscale.


clc;
clear all;
close all;
img=uigetfile('*.jpg');
a=imread(img);

Method 1:Pixel to Pixel conversion:

R=a(:,:,1);
G=a(:,:,2);
B=a(:,:,3);
for i=1:1:600
for j=1:1:800
GRAY(i,j)=(0.3*R(i,j))+(0.59*G(i,j))+(0.11*B(i,j));
end
end

Method 2: Averaging

GRAY=(R+G+B)/3;

Method 3: Luminance formula:

GRAY=(0.3*R)+(0.59*G)+(0.11*B);

FUNDAMENTALS OF IMAGE PROCESSING


(8 SEMESTER - ELECTRONICS & COMMUNICATION ENGINEERING)
NAME : OHM JODHANI
DIVISION:-CX BATCH:-C2 ROLL NO.:-32
ATMIYA INSTITUTE OF TECHNOLOGY & SCIENCE, RAJKOT.
TH

Experiment 0

BASICS

Method 4: Inbuilt MATLAB function:

GRAY=rgb2gray(a);
imshow(GRAY);

3. Write a MATLAB code to convert RGB image to Monochrome/Binary/Black and White


image.
clc;
clear all;
close all;
a=uigetfile('*.jpg');
imread(a);
for i=1:1:600
for j=1:1:800
X=(0.3*R(i,j))+(0.59*G(i,j))+(0.11*B(i,j));
if (X>150)
GRAY(i,j)=1;
else
GRAY(i,j)=0;
end
end
end
OR:
abw=im2bw(a);
imshow(abw);

FUNDAMENTALS OF IMAGE PROCESSING


(8 SEMESTER - ELECTRONICS & COMMUNICATION ENGINEERING)
NAME : OHM JODHANI
DIVISION:-CX BATCH:-C2 ROLL NO.:-32
ATMIYA INSTITUTE OF TECHNOLOGY & SCIENCE, RAJKOT.
TH

You might also like