검은 색/흰색 이미지 I0
(512 x 512)이 있는데이 이미지에서 첫 번째 k
픽셀을 제거하고 결과 이미지의 히스토그램을 계산해야합니다.히스토그램이 너무 달라야합니다.
내가 설명하자면, 픽셀을 고려하지 않고 I0
이미지의 막대 그래프를 만들어야합니다.
k = 8;
% compute the histogram of the entire image I0
[vecComp, histComp] = histKtoEnd(I0, 0, k);
% compute the histogram of the image I0 without the first k pixel
[vecWithoutKPixel, histWithoutKPixel] = histKtoEnd(I0, k, k);
:
이
내 코드입니다subplot(1, 2, 1);
bar(0:2^k-1, histComp, 'r');
title('Histogram of the entire image');
axis([minColor, maxColor, 0, numberOfPixels]);
subplot(1, 2, 2);
bar(0:2^k-1, histWithoutKPixel, 'r');
title('Histogram of the image without the first k pixels');
axis([minColor, maxColor, 0, numberOfPixels]);
내가 얻을 :
function [vecWithoutKPixel, hist] = histKtoEnd(image, k, colorDepth)
% image to row vector
imageVec = reshape(image.', [], 1);
l = length(imageVec);
% I "delete" the first k pixel
vecWithoutKPixel = imageVec((k+1) : l-1);
vecWithoutKPixel(end+1) = imageVec(l);
% inizialization
hist = zeros(1, 2^colorDepth);
% create the vector of occurrences
for i = 0 : (2^colorDepth - 1)
grayI = (vecWithoutKPixel == i);
hist(1, i+1) = sum(grayI(:));
end
end
알 수 있듯이 히스토그램은 매우 다르지만 그 차이는 단지 8 픽셀이기 때문에 거의 차이가 없어야합니다.
어디서 잘못 되었나요?
또한 warkspace에서 새로 만든 변수는 이러한 치수가 :
vecComp -> 262144 x 1 uint8
histComp -> 1 x 256 double
vecWithoutKPixel -> 65528 x 1 uint8
histWithoutKPixel -> 1 x 256 double
이 매우 이상하다. 나는 가지고 있어야한다 :
vecComp -> 262144 x 1
vecWithoutKPixel -> 262136 x 1
누군가 나를 도울 수 있었느냐? 내가 DICOM 이미지와 함께 일하고 있어요 및 명령 info = dicominfo(filename)
이
size = info.FileSize; % 262582;
colorType = info.ColorType; % grayscale
가 그래서 문제가 이미지라고 생각하지 않습니다 얻을 당신에게
감사드립니다. I 라인 vecWithoutKPixel(end+1) = imageVec(l);
에 brakpoint을 넣으면
나는 imageVec
가 262144 X 1 UINT8 것을 얻고, :
function [vecWithoutKPixel, hist] = histKtoEnd(image, k, colorDepth)
% image to row vector
imageVec = reshape(image.', [], 1);
l = length(imageVec);
size(imageVec) % 262144 x 1
% I "delete" the first k pixel
vecWithoutKPixel = imageVec((k+1) : l-1);
vecWithoutKPixel(end+1) = imageVec(l);
% inizialization
hist = zeros(1, 2^colorDepth);
% create the vector of occurrences
for i = 0 : (2^colorDepth - 1)
grayI = (vecWithoutKPixel == i);
hist(1, i+1) = sum(grayI(:));
end
end
것은 내가 명령 vecWithoutKPixel = imageVec((k+1) : l);
와 vecWithoutKPixel = imageVec((k+1) : l-1); vecWithoutKPixel(end+1) = imageVec(l);
내가 vecWithoutKPixel = []
것을 얻을 변경하는 경우.
'vecWithoutKPixel = imageVec ((k + 1) : l-1);'줄에 중단 점을 넣고'size (imageVec)'를 사용하여'imageVec'의 크기를 검사 할 수 있습니까? 또한 1)'(k + 1) : (l-1)'이 다를 수도 있고 2) 왜 마지막 요소를 "지우고"다시 넣었습니까? – Yvon
그리고'imageVec = image (:);'시도하십시오. – Yvon
글쎄 진짜 문제는 이미지 데이터에 있습니다. 나는 B/W 그림을 다루고 있다고 믿지만 Matlab에서는 RGBA 이미지로 저장됩니다. 이것은 원본 이미지의 크기로 볼 수 있습니다. 먼저 B/W로 변환해야합니다. – Yvon