简体   繁体   中英

need to plot a 2D graph of the gray image intensity in matlab

what I am trying is to compare two gray scale images by ploting their intensity into graph. The code is bellow is for single image.

img11 = imread('img.bmp');
[rows cols ColorChannels] = size(img11); 
for i=1:cols
    for j=1:rows 
        intensityValue = img11(j,i);
    end
end
% below trying different plot method
plot(intensityValue);
plot(1:length(img11),img11);
plot(img11(:))

My expected result for two images is like below pictures: here

not like this here

Based on your code you should be able to do the following.

img11 = imread('img1.bmp');
img22 = imread('img2.bmp');
figure;
imagesc(img11); % verify you image

figure;
plot(img11(:)); hold on;
plot(img22(:));

Using the command (:) will flatten a matrix into a single vector starting at the top left and going down in columns. If that is not the orientation that you want you try to rotate/transpose the image (or try using reshape() , but it might be confusing at the start). Additionally, if your image has large variations in the pixel intensity moving average filter can be useful.

Len = 128;
smooth_vector = filter(ones(Len,1)/Len,1,double(img11(:)));
figure; plot(smooth_vector);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM