Matlab 学習 1 画像処理グレースケール

画像処理、グレースケール処理
1. 画像の縮小
効果は次のとおりです。
ここに画像の説明を挿入
test.m のコードは次のとおりです。

%imresize改变图像大小

j=imread('img.jpg');%读取图片
img1=imresize(j,[256,256]);
subplot(2,2,1),imshow(img1),xlabel('a图,256*256,256灰度级');

img2=imresize(img1,0.5,'nearest');%图像处理,参数(图片,放大缩小,方法)
subplot(2,2,2),imshow(img2),xlabel('b图,128*128,256灰度级');%摆放图像位置

img3=imresize(img2,0.5,'nearest');
subplot(2,2,3),imshow(img3),xlabel('c图,64*64,256灰度级');

img4=imresize(img3,0.5,'nearest');
subplot(2,2,4),imshow(img4),xlabel('d图,32*32,256灰度级');

 imwrite(img1, 't1a.png');
 imwrite(img2, 't1b.png');
 imwrite(img3, 't1c.png');
 imwrite(img4, 't1d.png');

2. グレースケール画像の詳細な処理により、
次のような効果が得られます。
ここに画像の説明を挿入

test.m コードは次のとおりです。

J=imread('img.jpg');    % 2215*2956
J=rgb2gray(J);%将打开的图像转换为灰度图rgb2gray
Img=imresize(J,[256,256]);    % 256*256

imwrite(Img, 't3a.png', 'Bitdepth', 8);   % Bitdepth = 8
imwrite(Img, 't3b.png', 'Bitdepth', 4);   % Bitdepth = 4
imwrite(Img, 't3c.png', 'Bitdepth', 2);   % Bitdepth = 2

Black = find( im2bw(Img)==0 );
White = find( im2bw(Img)==1 );
Img(Black)=0;
Img(White)=170;

imwrite(Img, 't3d.png');   % Bitdepth = 8 ,但看起来 Bitdepth = 1

I1=imread('t3a.png');
I2=imread('t3b.png');
I3=imread('t3c.png');
I4=imread('t3d.png');
subplot(2,2,1),imshow(I1),xlabel('(a) 256×256,256级灰度');
subplot(2,2,2),imshow(I2),xlabel('(b) 256×256,16级灰度');
subplot(2,2,3),imshow(I3),xlabel('(c) 256×256,4级灰度');
subplot(2,2,4),imshow(I4),xlabel('(d) 256×256,2级灰度');

マテリアル コードは次のとおりです。
gitee: https://gitee.com/CYFreud/matlab/tree/master/image_processing

おすすめ

転載: blog.csdn.net/CHengYuP/article/details/123784664