Vous êtes sur la page 1sur 5

Command for newborn baby

>> x=imread('C:\Users\Phantomhive98\Documents\ISU MOODLE\Introduction to Digital Image


Processing\Homework\newborn.png');
>> x=imresize(x,[256 256]);

>> x=rgb2gray(x);
>> subplot(3,3,1);imshow(x);

>> subplot(3,3,2);imshow(imresize(imresize(x,1/2),2));
>> subplot(3,3,3);imshow(imresize(imresize(x,1/4),4));

>> subplot(3,3,4);imshow(imresize(imresize(x,1/8),8));
>> subplot(3,3,5);imshow(imresize(imresize(x,1/16),16));

>> subplot(3,3,6);imshow(imresize(imresize(x,1/32),32));

Command for camera man


>> c=imread(‘cameraman.tif’);
>> cd=double(c);

>> c0=mod(cd,2); subplot(3,3,1); imshow(c0); title(‘C0’);


>> c1=mod(floor(cd/2) ,2); subplot(3,3,2); imshow(c1); title(‘C1’);

>> c2=mod(floor(cd/4) ,2); subplot(3,3,3); imshow(c2); title(‘C2’);


>> c3=mod(floor(cd/8) ,2); subplot(3,3,4); imshow(c3); title(‘C3’);

>> c4=mod(floor(cd/16) ,2); subplot(3,3,5); imshow(c4); title(‘C4’);


>> c5=mod(floor(cd/32) ,2); subplot(3,3,6); imshow(c5); title(‘C5’);

>> c6=mod(floor(cd/64) ,2); subplot(3,3,7); imshow(c6); title(‘C6’);


>> c7=mod(floor(cd/128) ,2); subplot(3,3,8); imshow(c7); title(‘C7’);
Command for Image Editing
%Step 1: Read the Image into the Workspace;
I = imread('rice.png');
subplot(2,4,1);imshow(I);title('Rice Image');

%Step 2: Preprocess the Image to Enable Analysis;


background = imopen(I,strel('disk',15));
subplot(2,4,2);imshow(background);title('Background Image');

I2 = I - background;
subplot(2,4,3);imshow(I2);title('Without Background');
subplot(2,4,5);imhist(I2);title ('Intensity Histogram');

level = graythresh(I2);
bw = im2bw(I2,level);
I3 = bwareaopen(bw, 50);
subplot(2,4,6);imshow(I3);title('Rice Only');

%Step 3: Perform Analysis of Objects in the Image;


cc = bwconncomp(I3, 4);
cc.NumObjects

labeled = labelmatrix(cc);
RGB_label = label2rgb(labeled, @spring, 'c', 'shuffle');
subplot(2,4,7);imshow(RGB_label);title('Colour Rice');

graindata = regionprops(cc, 'basic');


grain_areas = [graindata.Area];
subplot(2,4,[4,8]);histogram(grain_areas,nbins);title('Histogram of Rice
Grain Area');
Command for Rice
clear; close all; clc;
%Step 1: Read the Image into the Workspace
I = imread('rice.png');
subplot(2,4,1);imshow(I); title('Rice Image');

%Step 2: Prepocess the Image to Enable Analysis


background = imopen(I,strel('disk',15));
subplot(2,4,2);imshow(background); title('Background Image');
I2 = imadjust(I - background);
subplot(2,4,3);imshow(I2); title('Removed Background');
subplot(2,4,5);imhist(I2); title('Intensity Histogram');
level = graythresh(I2);
bw = im2bw(I2,level);
I3 = bwareaopen(bw, 50);
subplot(2,4,6);imshow(I3); title('Rice Only');

%Step 3: Perform Analysis of Objects in the Image


cc = bwconncomp(I3, 4);
cc.NumObjects
labeled = labelmatrix(cc);
RGB_label = label2rgb(labeled, @spring, 'c', 'shuffle');
subplot(2,4,7);imshow(RGB_label);title ('Colour Rice');
graindata = regionprops(cc,'basic');
grain_areas = [graindata.Area];
subplot(2,4,[4,8]); hist(grain_areas);title('Histogram of Rice Grain
Area');

Command for Pushbutton.Callback (w hist)


imgname = char(get(handles.edit1,'String'));
x=imread(imgname);
%Values = str2double(char(get(handles.edit2,'String')));
Gamma = str2double(char(get(handles.edit2,'String')));
imshow(x, 'Parent',handles.axes1);
imhist(x);axes(handles.axes4);

y = imadjust(x, [0 1], [1 0]);


imshow(y, 'Parent',handles.axes2);
imhist(y);axes(handles.axes5);

z = imadjust(x, [], [], Gamma);


imshow(z, 'Parent',handles.axes3);
imhist(z);axes(handles.axes6);

Outstr = ['Gamma=',num2str(Gamma)];
set(handles.text11,'String', Outstr);

Command for Pushbutton.Callback (w/o hist)


imgname = char(get(handles.edit1,'String'));
x=imread(imgname);
Values = str2double(char(get(handles.edit2,'String')));
Constent = str2double(char(get(handles.edit3,'String')));
imshow(x*Values+Constent);

if(Constent>=0)
Strout=['Processing function:
Y=',num2str(Values),'*X+',num2str(Constent)];
else
Strout=['Processing function:
Y=',num2str(Values),'*X',num2str(Constent)];
end
set(handles.text9,'String', Strout);
Command for RX & RY value (exam)
imgname=char(get(handles.edit3,'String'));
x=rgb2gray(imread(imgname));

rx=str2num(char(get(handles.edit1,'Str')));disp(rx);
ry=str2num(char(get(handles.edit2,'Str')));disp(ry);

f1=@(x1,x2,y1,y2,x)(y1+(x-x1).*(y2-y1)/(x2-x1));
z=x;
for i=2:length(rx)
I=(x>=rx(i-1)&x<rx(i));
z(I)=f1(rx(i-1),rx(i),ry(i-1),ry(i),x(I));
end
subplot(1,2,1,'Parent',handles.uipanel1);
imshow(x);title('Input img');
subplot(1,2,2,'Parent',handles.uipanel1);
imshow(z);title('Output img');