Plot a 3D histogram with 3 arrays (vectors) of different sizes
7 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I need your help today because I am in a big difficulty :
My first array named i(of size 1,255)represent the grayscale values of my image. For each value of i, I have an array (of size 1,??). the '??' represent the number of pixels that have the value of i. So I have 255 vectors named number (a matrix if we want). And, for each value of a vector number I have another array that contains the errors of each particles.
For example, for the value of i(1)=1 I have size(number(i==1))=25 and so 25 errors. for the value of i(2)=2 I have size(number(i==2))=5 and so 5 errors, for the value of i(233)=233 I have 45 pixels and so 45 errors.
For one value of intensity I have different size vector number and errors.
So, I want to plot in a 3 dimension histogram these 3 variables. In the x axis I want the intensities 'i', for the y axis I want the number of pixels 'number' for each 'i' and for the z axis I want the error for each particle of number.
I hope you will understand my problem. Sorry for my poor English .. Thanks a lot.
0 个评论
回答(1 个)
Vandana Rajan
2016-8-8
Hi, Suppose you have an 8*8 gray scale image (64 pixels in total). So the x axis varies from 1 to 255 and y axis from 1 to 64, since the maximum number of pixel count corresponding to one gray scale value can be only 64. Make an error matrix of size 64X255. The matrix will be sparse, since most of the values are going to be zero. Make a bar graph as shown in http://www.mathworks.com/help/matlab/ref/bar3.html.
Sample code:
>> clearvars; close all; clc;
%%get an image
>> im = imread('coins.png');
>> im = imresize(im,[8,8]);
>> figure;imshow(im);
%%add noise to image
>> im_noisy = imnoise(im,'gaussian');
>> figure; imshow(im_noisy);
>> x_lim = 255;
>> y_lim = 8*8;
>> err = zeros(y_lim,x_lim);
>> for i = 1:y_lim
>> err(i,im(i)) = abs(double(im(i))-double(im_noisy(i)));
>> end
>> figure; bar3(err);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Histograms 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!