【问题标题】: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 imageMATLAB 绘制图像,8 种颜色的索引图像,第一个图上的 8 个颜色框和索引,在第二个图上绘制图像的 0-7 个索引作为图像
【发布时间】:2020-12-28 08:03:39
【问题描述】:

好的,我们有一个图像和(0,1,2,3,4,5,6,7) - 作为图像,我们需要显示我们拥有的图像,右下角,用数字重绘的图像(0,1,2,3,4,5,6,7),右边第三个,是pallete (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

任务应该怎么看第二个图:

【问题讨论】:

    标签: matlab matlab-figure


    【解决方案1】:

    图 1:调整大小并减少唯一颜色数

    就目前的实施细节而言,这就是我想出的。可以使用imresize() 函数和'nearest' 邻域插值来调整图像大小。为了减少颜色的数量,imapprox() 函数用于将唯一颜色的数量限制为 8。可以使用New_Image_Data(色卡键)和New_Colour_Map(色卡值)来重建新图像)。

    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 运行

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-18
      • 2011-05-12
      相关资源
      最近更新 更多