当前位置: 首页 > 知识库问答 >
问题:

Matlab-绘制特定像素(图像处理)

闻人浩波
2023-03-14

>

  • 我有一张NxM大小的原始图像(FigureB-它是原始图像的蓝色香奈儿),从这张图像中我选择一个特定的区域来研究(NewfigureB),大小120x170;

    然后我将这个区域划分为我所说的宏像素,即10x10的数据点(像素)阵列;

    我然后在所选区域上涂上掩膜,只选择符合一定发光条件的点;

    到目前为止,这是我想出来的。如有任何帮助,将不胜感激。

    多谢

    %Make the number of pixels in the matrix divisible
    Macropixel = 10; %determine the size of the macropixel
    [rows,columns] = size(figureB); %determine dimentions of the matrix used in the calculations
    MacropixRows = floor(rows/Macropixel); %determine how many macropixels are in a row of the original matrix
    MacropixColumn = floor(columns/Macropixel); %determine how many macropixels are in a column of the original matrix
    
    %define new dim for the matrix
    rows = MacropixRows * Macropixel;
    columns = MacropixColumn * Macropixel;
    NewfigureB = figureB(1:rows,1:columns); %divisible by the size of the macropixels created
    
    %select area 
    NewfigureB = NewfigureB(1230:1349,2100:2269);
    
    %create luminescence mask
    Lmin=50;
    hmax=80;
    mask=false(size(NewfigureB));
    mask(NewfigureB <Lmin)=true;
    mask=mask & (NewfigureB<hmax);
    
    %Apply mask
    NewfigureB=NewfigureB(mask);
    
    
        for jj = 1:Macropixel:120
            for ii =1:Macropixel:170 
            histogram( NewfigureB(jj:jj+Macropixel-1, ii:ii+Macropixel-1))
            end
        end'''
    
    
    
  • 共有1个答案

    壤驷安和
    2023-03-14

    您发布的代码有太多问题。

    我尽力更正了它。
    我修改了一些参数来模拟我使用的示例图像。
    我找不到您的示例图像,所以我使用了以下内容

    这里有一个更正的代码(请阅读注释):

    I = imread('Nikon-D810-Image-Sample-7.jpg');
    
    figureB = I(:,:,3);
    
    %Make the number of pixels in the matrix divisible
    Macropixel = 10; %determine the size of the macropixel
    [rows,columns] = size(figureB); %determine dimentions of the matrix used in the calculations
    MacropixRows = floor(rows/Macropixel); %determine how many macropixels are in a row of the original matrix
    MacropixColumn = floor(columns/Macropixel); %determine how many macropixels are in a column of the original matrix
    
    %define new dim for the matrix
    rows = MacropixRows * Macropixel;
    columns = MacropixColumn * Macropixel;
    NewfigureB = figureB(1:rows,1:columns); %divisible by the size of the macropixels created
    
    %select area 
    NewfigureB = NewfigureB(1230:1349,2100:2269);
    
    %create luminescence mask
    Lmin=90;%50; %Change to 90 for testing
    hmax=200;%80; %Change to 200 for testing
    mask=false(size(NewfigureB));
    mask(NewfigureB > Lmin)=true; %I think it should be > Lmin.   %mask(NewfigureB <Lmin)=true;
    mask=mask & (NewfigureB<hmax);
    
    %This is not the right way to apply a mask, because the result is a vector (not a matrix).
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %Apply mask
    %NewfigureB=NewfigureB(mask);
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    %Assuming there are no zeros in the image, you can set masked elements to zero:  
    NewfigureB(~mask) = 0;
    
    
    
    for jj = 1:Macropixel:120
        for ii =1:Macropixel:170
    
            %Copy NewfigureB(jj:jj+Macropixel-1, ii:ii+Macropixel-1) into temporary matrix MB:
            MB = NewfigureB(jj:jj+Macropixel-1, ii:ii+Macropixel-1);
    
            %Remove the zeros from MB (zeros are masked elements).
            %The result is a vector (not a matrix).
            MB = MB(MB ~= 0);
    
            %histogram( NewfigureB(jj:jj+Macropixel-1, ii:ii+Macropixel-1))
            figure; %Open new figure for each histogram. (I don't know if it's a good idea).
            histogram(MB); %Plot the histogram of vector MB.
        end
    end
    
     类似资料:
    • 假设我有一个像素化的图像……我想用处理来重画它。 起初应该有一个随机的彩色像素网格——过了一段时间,像素化的图像会通过这个像素化的网格出现。 我想我可以用这样的系统来处理这个问题:如果一个特定的随机颜色的像素与像素化图像的颜色相匹配,那么应该会有一个新的像素被绘制出来。 为了更好地理解,请看一下这段代码: 所以我能够在颜色匹配的情况下绘制像素——但是因为彩色噪声是随机绑定的——它们会再次消失……我

    • 除了绘制矢量图形和文本之外,canvas还提供了极为丰富的图像支持。开发者可以选择绘制某幅图像的全部或某个部分,在绘制时可以进行缩放或保持原样,可以把图像绘制到画布的任何地方。同时,还允许开发人员直接访问画布的像素数据。数据访问是双向的,既可以获取画布中的像素数据,也可以把像素重新绘制到画布中。 Canvas的API提供了如下4个用于绘制及操作图像的方法: drawImage():把图像、或另一个

    • 通过绘制一幅简单的图像,让我们直奔主题。本节,我们将学习如何加载一幅图像,并把它绘制到画布的某个地方。 图3-1 绘制图像 绘制步骤 按照以下步骤,在画布中央绘制一幅图像: 1. 定义画布上下文: window.onload  = function(){ var canvas  = document.getElementById("myCanvas"); var context  = c

    • 2D 绘图上下文内置了对图像的支持。如果你想把一幅图像绘制到画布上,可以使用drawImage()方法。根据期望的最终结果不同,调用这个方法时,可以使用三种不同的参数组合。最简单的调用方式是传入一个HTML <img>元素,以及绘制该图像的起点的x 和y 坐标。例如: var image = document.images[0]; context.drawImage(image, 10, 10);

    • 我是新来的。我正在尝试更改颜色(或其他参数,如色调、饱和度…)每个像素周围的像素。 我没有得到任何改变,而是得到了想要的结果。求求你,帮帮任何人(

    • 我正在研究图像加密和解密算法。我想使图像像素失真。我想要得到每一个像素值,然后按我想要的方式排序这些像素值,这样图像的像素被扭曲,图像被改变。我是在朝仪式的方向走吗?有什么提示吗?或者可以帮助我的示例算法。 我有一个像素的图像。表示图像由像素组成。如果我选择图像的第一个像素行,它是像素,我将这些像素转换为二进制,然后转换为十进制。现在我得到10个像素的十进制值。我按我想要的方式对这些值进行排序。现