|
clc;
clear all;
close all;
%?set path
dir1=cd;
addpath(dir1); % addpath '../.';
% addpath(genpath(pwd)) or addpath(genpath(cd)) for all subfolders
% addpath: add directory to search path; addpath Dir1 Dir2 Dir3 ...
% creat a new folder for outputs
out_dir='./out_fig/'; % path, note the ending separator
% ./? current folder; ./.../ subfolder
if (exist(out_dir,'dir')==0) % exist('A'), returning 0 if A does not exist
mkdir(out_dir); % make a new directory in the current folder
% [...]=mkdir(parentDir,newDir)
end
% read the raw image
A=imread('Ondra_sampling','jpg'); % read the iamge in the current folder
% A=imread(filename,format) or A=imread(filename), filename or filename.fmt
image(A); % Be careful diplaying a 2-D matrix using image
% image(C) displays matrix C of double, uint8 or uint16 class as an image
% places the center of pixel (M,N) at the coordinate (M,N)
% but the displayed image cannot be scaled in proportion along x and y aixs
axis image; % combination of axis tight and axis equal
axis off;
% x-, y- axis fills the position rectangle, equal tick mark increments
title('Input image');
% export the image
print('-r300','-depsc',[out_dir,'Ondra']); % device driver always starts with '-d'
% print(fmt, res,fname), print('-dpsc','-r200',[folder,fname])
% or command line: print -fhandle -rresonlution -dformate filename
% colormap
Agray=rgb2gray(A); % Agray: 2-D matrix, seen as indexed image
figure;
image(Agray); % the matrix elements are used as indices into colormap
% direct CDataMapping property by default
colormap(gray(256)); % get a gray image
% colormap(map); map: rows*3 (columns)
axis off
% line segment
% create a line segment between pixels (460,140) and (872,457),
% values given in (row,column) coordinates
r1 = 460; c1 = 140; r2 = 872; c2 = 457;
% draw the line to the picture
line( [r1, r2], [c1, c2], 'Color','r', 'LineWidth',3 ); % create line
% line(X,Y) adds the line in vectors X and Y to the current axes
print('-r300','-depsc',[out_dir,'OndraGray.eps']) ;
% calculate and display the intensity profile along the line segment
figure; improfile(Agray, [r1, r2], [c1, c2]); % C = improfile(I,xi,yi,N)
% N, if omitted, is roughly equal to the number of pixels the path traverses
ylabel('Pixel value');
title('Intensity profile along the line segment');
print('-r300','-depsc',[out_dir,'OndraGrayProfile.eps']) ;
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2025-1-8 12:38
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社