使用Matlab生成中心对称图形

时间:2022-01-12 06:17:53
img = zeros(256,256,'uint8');
for ii = 1:256
    img(:,ii)= ii-1;
end

imwrite(img,'gray-level256.bmp');
imwrite(img,'gray-level256.png');
imwrite(img,'gray-level256.jpg','Quality',0);
img_bmp = imread('gray-level256.bmp');
img_png = imread('gray-level256.png');
img_jpg = imread('gray-level256.jpg');
isequal(img,img_bmp)
isequal(img,img_png)
isequal(img,img_jpg)

img_diagonal1 = zeros(256,256,'uint8');
for ii = 1:256
    img_diagonal1(ii:end,ii) = 0:256-ii;%column
    img_diagonal1(ii,ii:end) = 0:256-ii;%row
end
figure,imshow(img_diagonal1);title('diagonal image');

img_diagonal2 = zeros(256,256,'uint8');
for ii = 1:256
    img_diagonal2(ii:end,256-ii+1) = 0:256-ii;%column
    img_diagonal2(ii,256-ii+1:-1:1) = 0:256-ii;%row
end

figure,imshow(img_diagonal2);title('diagonal image');
img_diagonal = double(img_diagonal1) + double(img_diagonal2);
img_diagonal = mat2gray(img_diagonal);

figure,imshow(1-img_diagonal);title('diagonal image');

使用Matlab生成中心对称图形