Basic image processing in Matlab
%% Image Creation. You have to thing reversely because background is write or 255 or true.
% size of creating image
rows = 500;
columns = 500;
% creating write image
grayImage = zeros(rows, columns, 'uint8');
grayImage(:) = 255;
%drawing shape. I am drawing equilateral triangle.
xCoords = [50 50 400]; % x1 , x2 ,x3
yCoords = [50 450 250]; % y1 , y2 , y3
mask = poly2mask(xCoords, yCoords, rows, columns); %first
node(x1,y1), second node(x2,y2), third node(x3,y3) AND
size
grayImage(mask) = 0; % or whatever value you want.
% some operations.
% we are using negatif image so that we have to think
reverse
symmetry=fliplr(grayImage); %symmetry of image
intersection=bitor(grayImage,symmetry); % like this matchingPixels =
(double(grayImage) + double(symmetry)) == 0;
association=bitand(grayImage,symmetry);
%% Showing Images
figure;
ax1=subplot(2,2,1);
imshow(grayImage);
title('orjinal');
ax2=subplot(2,2,2);
imshow(symmetry);
title('symmetry');
ax3=subplot(2,2,3);
imshow(intersection);
title('intersection');
ax4=subplot(2,2,4);
imshow(association);
title('association(km player in linux :) )');
linkaxes([ax1,ax2,ax3,ax4],'xy')
%% taking a photo from webcam
clear cam
cam=webcam;
webcamlist;
cam.AvailableResolutions;
%preview(cam);
img = snapshot(cam);
closePreview(cam) % closes video stream
clear cam % also closes video stream
gray=rgb2gray(img);
imwrite(img,'img.png');
%% shows the orjinal and gray scale images
figure('Name','shows the orjinal and gray scale images');
subplot(2,1,1)
imshow(img)
title('orjinal')
subplot(2,1,2)
title('gray')
imshow(gray);
pause(1);
close('shows the orjinal and gray scale images'); % or
close(n) ; n=1:inf
%% downsample by half
[rowsize, colsize]=size(gray);
Sampled2=gray(1:2:end,1:2:end);
Sampled2=imresize(Sampled2,[rowsize, colsize]);
[rowsize, colsize]=size(gray);
Sampled4=gray(1:4:end,1:4:end);
Sampled4=imresize(Sampled4,[rowsize, colsize]);
[rowsize, colsize]=size(gray);
Sampled8=gray(1:8:end,1:8:end);
Sampled8=imresize(Sampled8,[rowsize, colsize]);
[rowsize, colsize]=size(gray);
Sampled16=gray(1:16:end,1:16:end);
Sampled16=imresize(Sampled16,[rowsize, colsize]);
% imshow
figure('Name','shows downsampled images');
ax1=subplot(2,2,1);
imshow(Sampled2)
title('Sampled2')
ax2=subplot(2,2,2);
imshow(Sampled4)
title('Sampled4')
ax3=subplot(2,2,3);
imshow(Sampled8);
title('Sampled8')
ax4=subplot(2,2,4);
imshow(Sampled16);
title('Sampled16')
linkaxes([ax1,ax2,ax3,ax4],'xy')
pause(1);
%close('shows downsampled images'); %if you want to continue
process use it
Yorumlar
Yorum Gönder