⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exp04.m

📁 ARITHMETIC and LOGICAL OPERATION of images
💻 M
字号:
% % % % % % % % % % % % % % % % % % % % % % % % % %
%  Program for ARITHMETIC and LOGICAL OPERATION   %
% % % % % % % % % % % % % % % % % % % % % % % % % %

clc; clear all; close all;
%%%%% PART 1 %%%%%

%%%%%%%CONVERTING TO GREY SCALE IMAGE %%%%%%
%%% Reading the images
I1 = imread('img_01_Focus_left.bmp');
I2 = imread('img_02_Focus_right.bmp');

%%% Converting 'unit8' values to 'double'
Im1 = im2double(I1)*255;
Im2 = im2double(I2)*255;

% Seperating R,G and B components of img_01_Focus_left 
R1 = Im1(:,:,1);
G1 = Im1(:,:,2);
B1 = Im1(:,:,3);
% Converting to Gray Scale Image
IMAGE1 = 0.299*R1 + 0.587*G1 + 0.114*B1;
% Rounding 
IMAGE1 = round (IMAGE1);

% Seperating R,G and B components of img_01_Focus_right 
R2 = Im2(:,:,1);
G2 = Im2(:,:,2);
B2 = Im2(:,:,3);
% Converting to Gray Scale Image
IMAGE2 = 0.299*R2 + 0.587*G2 + 0.114*B2;
% Rounding 
IMAGE2 = round (IMAGE2);


%%% Finding difference image
Idiff = IMAGE1 - IMAGE2;

%%% Rescaling of difference image
Idiff_rescale = (Idiff + 255)/2;

%%% Mapping 
Idiff_max = max(max(Idiff));
Idiff_min = min(min(Idiff));     
Idiff_map = ((Idiff - Idiff_min) / (Idiff_max - Idiff_min)) *255;


%%% Display of images 
figure;
imshow(IMAGE1/255);title('Focus_left');
figure;
imshow(IMAGE2/255);title('Focus_right');
figure;
imshow(Idiff/255);title('Difference image');
figure;
imshow(Idiff_rescale/255);title('Rescaled Difference image');
figure;
imshow(Idiff_map/255); title('Mapped Difference image');




%%%%% PART 2 %%%%%

%%% Reading the images
I3 = imread('img_03_for_AND_OR.bmp');
I4 = imread('OR_mask.bmp');
I5 = imread('AND_mask.bmp');
figure;
imshow(I3);title('Dream Palace');

% Converting IMAGES to grayscale
I3 = rgb2gray(I3);
I4 = rgb2gray(I4);
I5 = rgb2gray(I5);
 
%%% Logical operations
I6_NOT = bitcmp(I3);               %%% NOT operation
I7_OR = bitor(I3,I4);              %%% OR  operation     
I8_AND = bitand(I3,I5);            %%% AND operation

I9 = I7_OR - I8_AND;               %%% DIFFERENCE image


%%% Display of images 
figure;
imshow(I3);title('Palace');
figure;
imshow(I6_NOT);title('NOT operation ');
figure;
imshow(I4);title('OR mask');
figure;
imshow(I7_OR);title('OR operation ');
figure;
imshow(I5);title('AND mask ');
figure;
imshow(I8_AND);title('AND operation ');
figure;
imshow(I9);title(' Difference of AND & OR operated image');



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -