my own imhist function error
3 次查看(过去 30 天)
显示 更早的评论
Hello, iam new in matlab, and i have some questions about this function i made. my teacher wants us to do our own imhist, and i did this. my question is, iam using a double image and it gives an error, what i should change in this function to works fine with double image.
( Attempted to access vetor(1.01519); index must be a positive integer or logical.)
function img2 = HistOnMyOwn(image)
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
img2=image;
im2double(img2);
vetor=zeros(256,1);
for i=1:size(img2,1)
for j =1:size(img2,2)
vetor(img2(i,j)+1) = vetor(img2(i,j)+1)+1;
end
end
plot(vetor);
end
0 个评论
采纳的回答
更多回答(1 个)
Image Analyst
2012-12-10
DO NOT use image as the name of your input argument - you'd be blowing away the important built-in image() function.
Your
im2double(img2);
line does nothing since it's not assigned to anything. Even if it did, it would do nothing because your image is apparently already a double in the range 0-1. You should do this instead:
img2 = uint8(255 * inputImage); % Using inputImage here instead of image.
Note: if your double image has values outside the 0-1 range, then you'll have to do things a little differently.
3 个评论
Image Analyst
2012-12-10
So img2(i,j)+1 is 1.05098???? I just don't see how img2(i,j) can possibly have the value 0.05098 when you multiplied it by 255 and rounded it to the nearest integer. It just doesn't make sense. It must be an integer in the range 0-255. Is there some code you're not sharing? Put this line inside your inner most for loop
fprintf('(i, j) = (%d, %d), img2(%d, %d) = %d\n',...
i, j, i, j, img2(i, j);
Tell me what you discover.
Image Analyst
2012-12-10
Hmmmm. You just accepted Sean's answer. Ok, I guess whatever the problem was, you finally figured it out.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!