MATLAB绘制图像,8种颜色的索引图像,第一个图上的颜色和索引的8个颜色框,第二个图上绘制图像的0-7个索引作为图像
MATLAB draw image, indexed image of 8 colors, 8 color boxes of color and index on first figure, on second figure draw 0-7 indexes of image as image
好的,我们有一个图像 (0,1,2,3,4,5,6,7)
- 作为图像,我们需要显示我们得到的图像,右下一个,按数字 (0,1,2,3,4,5,6,7)
重绘的图像,右第三个, 是调色板 (0,1,2,3,4,5,6,7)
和带颜色的盒子。
a) 上传 JPEG 图片。选择数量行 M
和数量列 N
用于绘制网格。根据所需的网格大小更改图像大小。
b) 将索引图像中的图像 .JPEG 转换为具有 8 种颜色并显示为图片。
c) 准备显示色卡的图像。
d) 准备显示网格和颜色编号的图像。
m = 80;
n = 60;
im = imresize(imread('1задание.jpg'), [m n] * 10, 'nearest');
small_im = imresize(im, [m n], 'nearest');
[X, map] = rgb2ind(small_im, 8);
big_small_im = im2uint8(ind2rgb(imresize(X, [m n] * 10, 'nearest'), map));
figure;
imshow([im ones(m * 10, 50, 3) * 255 big_small_im ones(m * 10, 50, 3) * 255 ...
generate_cool_map(map, m * 10)]);
digits = [];
for i = 0 : 7
digit = imread([int2str(i) '.png']);
digits = [digits digit];
end
pixel_s = 43;
final_im = im2uint8(ones(m * pixel_s, n * pixel_s, 3) * 255);
for i = 1 : m
for j = 1 : n
final_im((i - 1) * pixel_s + 1 : i * pixel_s, j * pixel_s, :) = zeros(pixel_s, 1, 3);
final_im(j * pixel_s, (j - 1) * pixel_s + 1 : j * pixel_s, :) = zeros(pixel_s, 1, 3);
final_im((i - 1) * pixel_s + 2 : (i - 1) * pixel_s + 2 + 39+4, (j - 1) * pixel_s + 2 : (j - 1) * pixel_s + 2 + 26, :) = digits(:, X(i, j) * 27 + 1 : (X(i, j) + 1) * 27, :);
end
end
figure;
imshow(final_im);
function res = generate_cool_map(map, s)
color_size = floor(s / 8);
m_map = zeros(8, 1, 3);
for i = 1 : 8
m_map(i, 1, :) = map(i, :);
end
res = imresize(m_map, [s, color_size], 'nearest');
res(:, 1:2, :) = zeros(s, 2, 3);
res(:, color_size - 1 : color_size, :) = zeros(s, 2, 3);
for i = 0 : 7
res(i * color_size + 1 : i * color_size + 2, :, :) = zeros(2, color_size, 3);
res(i * color_size + 1 + floor(color_size / 2) : i * color_size + 2 + ...
floor(color_size / 2),1:7,:) = zeros(2,7,3);
res(i * color_size + 1 + floor(color_size / 2) : i * color_size + 2 + ...
floor(color_size / 2), color_size - 6 : color_size, :) = zeros(2,7,3);
end
res(s - 1 : s, :, :) = zeros(2, color_size, 3);
res = [res ones(s, floor(color_size / 3), 3) * 255];
digits = [];
for i = 0 : 7
digit = imread([int2str(i) '.png']);
digits = [digits digit];
end
res = im2uint8(res);
for i = 0 : 7
res(i * color_size + floor(color_size / 3) : i * color_size + ...
floor(color_size / 3) + 39+4, color_size + 6 : color_size + 6 + 26, :) ...
= digits(:, i * 27 + 1 : (i + 1) * 27, :);
end
end
任务如何先看图:
我试过了,但似乎这里有些错误。 :c
第二个任务怎么看:
图 1:调整大小并减少唯一颜色数
根据目前的实施细节数量,这是我想出的。可以使用 imresize()
函数和 'nearest'
邻域插值来调整图像大小。为了减少颜色的数量,imapprox()
函数用于将唯一颜色的数量限制为 8。可以使用 New_Image_Data
(色卡键)和 [=16= 来重建新图像](色卡值)。
m = 50;
n = 60;
Original_Image = imread('peppers.png');
subplot(1,2,1); imshow(Original_Image);
title("Original Image");
Number_Of_Rows = m;
Number_Of_Columns = n;
%Resizing image%
Resized_Image = imresize(Original_Image,[m n],'nearest');
%Reducing the amount of colours%
Maximum_Intensity = 255;
[Image_Data,Colour_Map] = rgb2ind(Resized_Image,Maximum_Intensity);
[New_Image_Data,New_Colour_Map] = imapprox(Image_Data,Colour_Map,8);
subplot(1,2,2); imshow(New_Image_Data,New_Colour_Map);
title("Resized Image with 8 Colours");
Colour_Bar = colorbar;
set(Colour_Bar,'YTick',(0:7));
图 2:绘制值网格
%Plotting the grid of card colour values%
Figure_2 = figure(2);
clf;
Figure_2.Position = [0 0 700 700];
x = (0:Number_Of_Rows);
y = (0:Number_Of_Columns);
[X,Y] = meshgrid(x,y);
Z = ones(length(x),length(y)).';
mesh(Y,X,Z);
axis off
hold on
view(0,90);
Image_Data = flip(New_Image_Data);
title("Colour Card Values/Keys");
for Row_Index = 1: Number_Of_Rows
for Column_Index = 1: Number_Of_Columns
text(Column_Index-0.5,Row_Index-0.5,num2str(Image_Data(Row_Index,Column_Index)));
end
end
运行 使用 MATLAB R2019b
好的,我们有一个图像 (0,1,2,3,4,5,6,7)
- 作为图像,我们需要显示我们得到的图像,右下一个,按数字 (0,1,2,3,4,5,6,7)
重绘的图像,右第三个, 是调色板 (0,1,2,3,4,5,6,7)
和带颜色的盒子。
a) 上传 JPEG 图片。选择数量行 M
和数量列 N
用于绘制网格。根据所需的网格大小更改图像大小。
b) 将索引图像中的图像 .JPEG 转换为具有 8 种颜色并显示为图片。
c) 准备显示色卡的图像。
d) 准备显示网格和颜色编号的图像。
m = 80;
n = 60;
im = imresize(imread('1задание.jpg'), [m n] * 10, 'nearest');
small_im = imresize(im, [m n], 'nearest');
[X, map] = rgb2ind(small_im, 8);
big_small_im = im2uint8(ind2rgb(imresize(X, [m n] * 10, 'nearest'), map));
figure;
imshow([im ones(m * 10, 50, 3) * 255 big_small_im ones(m * 10, 50, 3) * 255 ...
generate_cool_map(map, m * 10)]);
digits = [];
for i = 0 : 7
digit = imread([int2str(i) '.png']);
digits = [digits digit];
end
pixel_s = 43;
final_im = im2uint8(ones(m * pixel_s, n * pixel_s, 3) * 255);
for i = 1 : m
for j = 1 : n
final_im((i - 1) * pixel_s + 1 : i * pixel_s, j * pixel_s, :) = zeros(pixel_s, 1, 3);
final_im(j * pixel_s, (j - 1) * pixel_s + 1 : j * pixel_s, :) = zeros(pixel_s, 1, 3);
final_im((i - 1) * pixel_s + 2 : (i - 1) * pixel_s + 2 + 39+4, (j - 1) * pixel_s + 2 : (j - 1) * pixel_s + 2 + 26, :) = digits(:, X(i, j) * 27 + 1 : (X(i, j) + 1) * 27, :);
end
end
figure;
imshow(final_im);
function res = generate_cool_map(map, s)
color_size = floor(s / 8);
m_map = zeros(8, 1, 3);
for i = 1 : 8
m_map(i, 1, :) = map(i, :);
end
res = imresize(m_map, [s, color_size], 'nearest');
res(:, 1:2, :) = zeros(s, 2, 3);
res(:, color_size - 1 : color_size, :) = zeros(s, 2, 3);
for i = 0 : 7
res(i * color_size + 1 : i * color_size + 2, :, :) = zeros(2, color_size, 3);
res(i * color_size + 1 + floor(color_size / 2) : i * color_size + 2 + ...
floor(color_size / 2),1:7,:) = zeros(2,7,3);
res(i * color_size + 1 + floor(color_size / 2) : i * color_size + 2 + ...
floor(color_size / 2), color_size - 6 : color_size, :) = zeros(2,7,3);
end
res(s - 1 : s, :, :) = zeros(2, color_size, 3);
res = [res ones(s, floor(color_size / 3), 3) * 255];
digits = [];
for i = 0 : 7
digit = imread([int2str(i) '.png']);
digits = [digits digit];
end
res = im2uint8(res);
for i = 0 : 7
res(i * color_size + floor(color_size / 3) : i * color_size + ...
floor(color_size / 3) + 39+4, color_size + 6 : color_size + 6 + 26, :) ...
= digits(:, i * 27 + 1 : (i + 1) * 27, :);
end
end
任务如何先看图:
我试过了,但似乎这里有些错误。 :c
第二个任务怎么看:
图 1:调整大小并减少唯一颜色数
根据目前的实施细节数量,这是我想出的。可以使用 imresize()
函数和 'nearest'
邻域插值来调整图像大小。为了减少颜色的数量,imapprox()
函数用于将唯一颜色的数量限制为 8。可以使用 New_Image_Data
(色卡键)和 [=16= 来重建新图像](色卡值)。
m = 50;
n = 60;
Original_Image = imread('peppers.png');
subplot(1,2,1); imshow(Original_Image);
title("Original Image");
Number_Of_Rows = m;
Number_Of_Columns = n;
%Resizing image%
Resized_Image = imresize(Original_Image,[m n],'nearest');
%Reducing the amount of colours%
Maximum_Intensity = 255;
[Image_Data,Colour_Map] = rgb2ind(Resized_Image,Maximum_Intensity);
[New_Image_Data,New_Colour_Map] = imapprox(Image_Data,Colour_Map,8);
subplot(1,2,2); imshow(New_Image_Data,New_Colour_Map);
title("Resized Image with 8 Colours");
Colour_Bar = colorbar;
set(Colour_Bar,'YTick',(0:7));
图 2:绘制值网格
%Plotting the grid of card colour values%
Figure_2 = figure(2);
clf;
Figure_2.Position = [0 0 700 700];
x = (0:Number_Of_Rows);
y = (0:Number_Of_Columns);
[X,Y] = meshgrid(x,y);
Z = ones(length(x),length(y)).';
mesh(Y,X,Z);
axis off
hold on
view(0,90);
Image_Data = flip(New_Image_Data);
title("Colour Card Values/Keys");
for Row_Index = 1: Number_Of_Rows
for Column_Index = 1: Number_Of_Columns
text(Column_Index-0.5,Row_Index-0.5,num2str(Image_Data(Row_Index,Column_Index)));
end
end
运行 使用 MATLAB R2019b