フィルターのクリア

IHS triangular model for RGB image

2 ビュー (過去 30 日間)
doaa yehia
doaa yehia 2023 年 11 月 19 日
編集済み: DGM 2023 年 12 月 22 日
i want to make fusion of MRI and PET images using IHS triangular model so first i want to convert PET image from RGB to IHS
can you help me with this . the error is that no values assigned to h and s
this my code :
function hsi_image = IHStriang(rgb_image)
% Convert the input RGB image to double precision
rgb_image = double(rgb_image);
% Extract the R, G, and B channels
R = rgb_image(:, :, 1);
G = rgb_image(:, :, 2);
B = rgb_image(:, :, 3);
% Calculate the intensity channel (I)
I = (R + G + B) / 3;
% Calculate the saturation channel (S) and hue channel (h)
for i = 1:256
for j = 1:256
if (B(i, j) < ((R(i, j) && G(i, j))))
h(i, j) = (G(i, j) - B(i, j)) ./ (3 .* I(i, j) - 3 .* B(i, j));
S(i, j) = (I(i, j) - B(i, j)) ./ I(i, j);
elseif ((R(i, j)) < (B(i, j)) && (G(i, j)))
h(i, j) = ((B(i, j) - R(i, j)) ./ (3 .* I(i, j) - 3 .* R(i, j)))+1;
S(i, j) = (I(i, j) - R(i, j)) ./ I(i, j);
elseif ((G(i, j)) < (B(i, j)) && (R(i, j)))
h(i, j) = ((R(i, j) - G(i, j)) ./ (3 .* I(i, j) - 3 .* G(i, j)))+2;
S(i, j) = (I(i, j) - G(i, j)) ./ I(i, j);
end
end
end
% Combine the H, S, and I channels to form the HSI image
hsi_image = cat(3, I, h, S);
end
  1 件のコメント
Walter Roberson
Walter Roberson 2023 年 11 月 19 日
編集済み: Walter Roberson 2023 年 11 月 19 日

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2023 年 11 月 19 日
  2 件のコメント
doaa yehia
doaa yehia 2023 年 12 月 2 日
thanks
DGM
DGM 2023 年 12 月 2 日
編集済み: DGM 2023 年 12 月 2 日
While those are both good resources, I should point out that neither cover information about HSx models, nor do they cover image fusion topics.

サインインしてコメントする。

その他の回答 (1 件)

DGM
DGM 2023 年 11 月 19 日
編集済み: DGM 2023 年 11 月 19 日
There are a few things wrong here.
First, the images are not RGB. One of them is indexed color, and the other is simply a grayscale image.
% this is a 128x128 indexed color image
fn1 = 'http://www.med.harvard.edu/AANLIB/cases/caseNN1/dg1/015.png';
[pet ct] = imread(fn1);
if ~isempty(ct)
pet = ind2rgb(pet,ct); % convert it to RGB if needed
end
size(pet)
ans = 1×3
128 128 3
% this is just a grayscale image (256x256x1)
fn2 = 'http://www.med.harvard.edu/AANLIB/cases/caseNN1/mr2/015.png';
[mri ct] = imread(fn2);
if ~isempty(ct)
mri = ind2rgb(mri,ct); % it's not indexed color, so it just stays gray
end
size(mri)
ans = 1×2
256 256
So unless you convert the PET image, you have no color information. The MRI image simply has no color information.
Your HSI conversion routine presumes that the images have the exact size 256x256x3, which neither image has. Your HSI conversion routine also performs invalid logical tests:
if (B(i, j) < ((R(i, j) && G(i, j)))) % this is nonsense
% ...
end
if (B(i, j) <= R(i, j)) && (B(i, j) <= G(i, j)) % this is makes sense
% ...
end
Because of this and the lack of preallocation, not only will H and S be wrong, the size of H and S will also generally be wrong, causing errors at concatenation. The loops are unnecessary, and are only made slower due to this lack of preallocation. You're also never testing for equality, so H and S will be full of tiny holes. The end result is inconsistently and incompatibly-scaled because you're not converting the input image to a consistent scale when you cast it to double. The output ranges (after fixing the conditionals) will be:
  • H_range = [0 3] (nonstandard)
  • S_range = [0 1]
  • I_range = getrangefromclass(rgb_image) (inconsistent)
That's what im2double() is for.
I don't know what you mean by "triangular IHS". At first glance, the code appears to be a bastardization of HSL, but with I substituted for V. I don't have a reference for any such thing. I have implementations for HSI and HSL as Walter linked above. MATLAB already has HSV conversions. Either way, I assume you need both forward and inverse transformations.
Lastly, I don't know what you mean by "fusion". That's one of those ugly vague words that gets used with what I assume is a specific underlying technical intent, but the word itself just means "combine two images somehow". There are probably hundreds of papers written on medical image fusion techniques that are beyond my ken, but when ever I see a question, it seems people don't seem to have any technical requirements other than jamming the two images into one.
  1 件のコメント
doaa yehia
doaa yehia 2023 年 12 月 2 日
ok,thank you.

サインインしてコメントする。

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by