Plot a 3D histogram with 3 arrays (vectors) of different sizes

7 ビュー (過去 30 日間)
Hidir ABAY
Hidir ABAY 2016 年 6 月 13 日
回答済み: Vandana Rajan 2016 年 8 月 8 日
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.

回答 (1 件)

Vandana Rajan
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);

カテゴリ

Help Center および File ExchangeHistograms についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by