使用MATLAB进行中位数,四分位数,四分位数跨度和分辨率

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用MATLAB进行中位数,四分位数,四分位数跨度和分辨率相关的知识,希望对你有一定的参考价值。

我在MATLAB中有一张图片并将其分解为R,G和B通道。现在我需要弄清楚分辨率,中位数,上下四分之一,四分之一跨度和模式。

这是我用它的代码:关闭所有; CLC;清除所有

I = imread('image_S006_I0000.jpg'); 
 imshow(I)                           


[R S T] = size(I);                  

Red(:,:,1)=I(:,:,1);
Red(:,:,2)=zeros(R,S);
Red(:,:,3)=zeros(R,S);

Green(:,:,1)=zeros(R,S);
Green(:,:,2)=I(:,:,1);
Green(:,:,3)=zeros(R,S);

Blue(:,:,1)=zeros(R,S);
Blue(:,:,2)=zeros(R,S);
Blue(:,:,3)=I(:,:,1);


OR

Red=double(I(:,:,1));
Red=zeros(R,S);
Red=zeros(R,S);

Green=zeros(R,S);
Green=double(I(:,:,1));
Green=zeros(R,S);

Blue=zeros(R,S);
Blue=zeros(R,S);
Blue=double(I(:,:,1));

OR
Red(:,:,1)=double(I(:,:,1));
Green(:,:,1)=double(I(:,:,1));
Blue(:,:,1)=double(I(:,:,1));


cat(3, uint8(Red), zeros(R, S), zeros(R, S));
others = zeros(R, S);
red_plt = cat(3, uint8(Red), others, others);
green_plt = cat(3, others, uint8(Green), others);
blue_plt = cat(3, others, others, uint8(Blue));

figure()
subplot(131);imshow(red_plt)
subplot(132);imshow(green_plt)
subplot(133);imshow(blue_plt)

NOW PLOTTITG (It doesn't print it in Red, Green and Blue color. First two 
are just all black, the third one is black and white):
figure()
subplot(131);imshow(uint8(Red))
subplot(132);imshow(uint8(Green))
subplot(133);imshow(uint8(Blue))


[x1 y1 z1] = size(I);   

% MEDIAN. 
imgmedianR = median (Red(:))
imgmedianG = median (Green(:))
imgmedianB = median (Blue(:))


%QUARTIL
r025 = quantile(Red,0.25) 
r075 = quantile(Red,0.75) 

g025 = quantile(Green,0.25) 
g075 = quantile(Green,0.75) 

b025 = quantile(Blue,0.25) 
b075 = quantile(Blue,0.75) 


%INTERQUARTIL SPAN
r_iqr = iqr(Red) 
g_iqr = iqr(Green) 
b_iqr = iqr(Blue) 


modus_Red = mode(Red(:))
modus_Green = mode(Green(:))
modus_Blue = mode(Blue(:))

MEDIAN:当我尝试计算MEDIAN时,它给了我一堆数字(实际上matlab分别打印出每列的数字)。那我做错了什么?

QUARTIL:与我在MEDIAN的代码中遇到的问题相同。那我做错了什么?

INTERQUARTIL SPAN:Matlab打印出后续错误:不支持混合整数类输入。我做错了什么?

解决方案:我需要使用Matlab找出图像的分辨率。我已经尝试了funciton imfinfo,但信息不包括在内。如何使用任何类型的Matlab函数找到这样的信息?

非常感谢你提前!

答案

您将每个单独的颜色保存在3d矩阵中。这不是必需的。要将它们保存在2d矩阵中,如下所示:

Red=double(I(:,:,1));

Green=double(I(:,:,2));

Blue=double(I(:,:,3));

请注意,有一个转换为double。那是iqr所需要的。也可以在每个函数中使用Red(:)而不是Red(当然其他颜色也一样)。如果你改变了这一切,它应该工作得很好。

关于分辨率,这只是高度和宽度的像素数,在你的情况下RS

ps你两次打电话给size(I)


如果分别绘制红色,绿色和蓝色,则需要制作与原始矩阵相同的矩阵,但只有1种颜色不为零。该图像是RxSx3矩阵。因此,如果您想绘制红色部分,您需要制作一个RxSx3矩阵,其中只有红色非零:

cat(3, uint8(Red), zeros(R, S), zeros(R, S));

所以总的来说应该是这样的

others = zeros(R, S);
red_plt = cat(3, uint8(Red), others, others);
green_plt = cat(3, others, uint8(Green), others);
blue_plt = cat(3, others, others, uint8(Blue));

figure()
subplot(131);imshow(red_plt)
subplot(132);imshow(green_plt)
subplot(133);imshow(blue_plt)

编辑:

整个代码:

I = imread('image_S006_I0000.jpg'); 
 imshow(I)                           

[R S T] = size(I);                  

Red=double(I(:,:,1));

Green=double(I(:,:,2));

Blue=double(I(:,:,3));

others = zeros(R, S);
red_plt = cat(3, uint8(Red), others, others);
green_plt = cat(3, others, uint8(Green), others);
blue_plt = cat(3, others, others, uint8(Blue));

figure()
subplot(131);imshow(red_plt)
subplot(132);imshow(green_plt)
subplot(133);imshow(blue_plt)


% MEDIAN. 
imgmedianR = median (Red(:))
imgmedianG = median (Green(:))
imgmedianB = median (Blue(:))


%QUARTIL
r025 = quantile(Red(:),0.25) 
r075 = quantile(Red(:),0.75) 

g025 = quantile(Green(:),0.25) 
g075 = quantile(Green(:),0.75) 

b025 = quantile(Blue(:),0.25) 
b075 = quantile(Blue(:),0.75) 


%INTERQUARTIL SPAN
r_iqr = iqr(Red(:)) 
g_iqr = iqr(Green(:)) 
b_iqr = iqr(Blue(:)) 


modus_Red = mode(Red(:))
modus_Green = mode(Green(:))
modus_Blue = mode(Blue(:))

以上是关于使用MATLAB进行中位数,四分位数,四分位数跨度和分辨率的主要内容,如果未能解决你的问题,请参考以下文章

什么是分位数,如何计算分位数?

通过查询计算 SQLiteDB 的下四分位数和上四分位数

如何计算第一和第三四分位数?

四分位数计算方法

四分位数计算以及使用pandas计算

pandas使用