Counting overlapping pixels between two images
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
I'm looking to find the number of overlapping shaded pixels between two images. The two images are attached. How could I count the overlapping shaded red pixels between the two images? Any assistance would be much appreciated. If possible an easily repeatable process, as I have to run it with 64 images.
採用された回答
Image Analyst
2014 年 7 月 18 日
Call imregister to align them. Then use min() to take the min values of the two images.
By the way, I'll be soon leaving for canoe camping over the weekend so good luck. I'll be back Sunday afternoon.
11 件のコメント
Matthew Alston
2014 年 7 月 18 日
Thanks for all your help, have a great trip!
Matthew Alston
2014 年 7 月 18 日
If you're still around could you quickly help me with what A would be in my case (using min(A,[],dim), right?)? I'm confused by the min help site.
A would be the two images stacked:
A = cat(3, image1, image2);
See if that works. If not, do it on each color channel one at a time.
Matthew Alston
2014 年 7 月 20 日
So here's my code so far. Am I on the right track? I'm not getting any error messages but I'm also not getting a min value when I run the script.
Image Analyst
2014 年 7 月 20 日
Not really. This will take a while to fix...
This is about all I had time for:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 13;
filename = {'CMHJ_A1FC';'CMHJ_A2FC';'CMHJ_A3FC';'CMHJ_A4FC';'CMHJ_A5FC';'CMHJ_A6FC';...
'CMHJ_A7FC';'CMHJ_A8FC';'CMHJ_B1FC';'CMHJ_B2FC';'CMHJ_B3FC';...
'CMHJ_B4FC';'CMHJ_B5FC';'CMHJ_B6FC';'CMHJ_B7FC';'CMHJ_B8FC'};
folder = 'C:\Users\Matt\Documents\Temporary';
fixedFileName = fullfile(folder, 'CMHJ_P1FC.jpg');
if ~exist(fixedFileName, 'file')
message = sprintf('Moving file name #%d does not exist:\n%s\nSkipping it.', k, fixedFileName);
uiwait(v(message));
return;
end
fixedReference = imread (fixedFileName);
subplot(1, 3, 1);
imshow(fixedReference);
title('Fixed Reference Image', 'fontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
drawnow;
for k = 1 : length(filename)
movingFileName = fullfile(folder, sprintf('%s.jpg', filename{k}));
if ~exist(movingFileName, 'file')
promptMessage = sprintf('Moving file name #%d does not exist:\n%s\nSkipping it.', k, movingFileName);
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');
if strcmpi(button, 'Cancel')
break;
end
continue;
end
movedImage = imread (movingFileName);
subplot(1, 3, 2);
imshow(movedImage);
caption = sprintf('Moved image: %s', filename{k});
title(caption, 'fontSize', fontSize, 'Interpreter', 'none');
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
drawnow;
% Register the moved image to the fixed, reference image.
% imshowpair (fixedReference, movedImage);
%
% fixedReference = rgb2gray (fixedReference);
% movedImage = rgb2gray (movedImage);
% [optimizer, metric] = imregconfig ('multimodal');
% movingRegisteredDefault = imregister (fixedReference, movedImage, 'affine', optimizer, metric);
% subplot(1, 3, 2);
% imshowpair (movingRegisteredDefault, movedImage)
% title('reg', 'fontSize', fontSize);
stackedImage = cat(3, movedImage, fixedReference);
minImage = min(stackedImage, [], 3);
subplot(1, 3, 3);
imshow(minImage);
title('Combined Image', 'fontSize', fontSize);
promptMessage = sprintf('Do you want to Continue processing,\nor Cancel to quit processing?');
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');
if strcmpi(button, 'Cancel')
break;
end
end
Matthew Alston
2014 年 7 月 21 日
Okay thanks for your help, hope you had a good canoe trip
mohamed seliga
2020 年 12 月 28 日
How to calculate overlap measure between two x-ray images , and the picture is attached to the message. Please answer a question. Thank you

Image Analyst
2020 年 12 月 28 日
mohamed, start a new question and attach your two original images, and the code that found the red and green coordinates. And clearly specify what is the overlap area you want. Is it the area that is common to both the green and red outlines regions
mohamed seliga
2020 年 12 月 28 日
I want the code that defines the green points on the mask, and calculates the overlap between the area that is common to both the green and red outlines regions, the code that I have specifies the red line only on the image

Image Analyst
2020 年 12 月 29 日
編集済み: Image Analyst
2020 年 12 月 29 日
Well just do something similar to get the green line. I'm not sure what is different - maybe a different parameter at some point in your algorithm. Then you can get the mask for each and AND them:
[rows, columns, numberOfColorChannels] = size(yourImage);
redMask = poly2mask(xRed, yRed, rows, columns];
greenMask = poly2mask(xGreen, yGreen, rows, columns];
overlap = redMask & greenMask;
overlapArea = nnz(overlap);
Again, let's take this to a different thread, so we don't keep sending Matthew emails about new activity in his 6 year old question. You can reply here ONCE again, ONLY to put the link to your new question.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Explore and Edit Images with Image Viewer App についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
