Finding max intensity pixel in image doesnt work in code
7 views (last 30 days)
Show older comments
Hello, I am a beginner so I can only work with basic code for now. The assignment was to use 2 pictures, get the difference between the two, then find the max intensity pixel, but as you can see from the percentage marks, I have tried many things and none have worked. If anyone has a suggestion please feel free to respond.
colormap('gray');
%displays plane 1 BMP
planes1pic = imread('planes1.bmp');
subplot( 4, 1, 1);
imagesc(planes1pic);
axis off
title('BEFORE');
%displays planes 2 BMP
planes2pic = imread('planes2.bmp');
subplot(4, 1, 2);
imagesc(planes2pic);
axis off
title('AFTER');
PROBLEM CODE BEGIN:
%finds the difference between the planes by subtratction, and finds the max
planesDiff = (planes1pic - planes2pic);
subplot(4, 1, 3);
imagesc(planesDiff);
axis off
title('DIFFERENCE');
hold on
%[rowsMax , colsMax] = find(planesDiff == max(planesDiff(:)));
% maxplanesDiff = max(max(planesDiff()));
%[xx , yy] = find(planesDiff == maxplanesDiff);
%plot(xx , yy, '.r');
%lol = find(planesDiff == max(max(planesDiff)));
%plot(lol , '.r');
%%[r, c] = find(planesDiff == max(planesDiff(:)));
%%plot(r , c, '.r');
[xx , yy] = max(max(planesDiff));
%[xx , yy] = find(planesDiff == maxVal);
plot(xx , yy , '.r');
PROBLEM CODE END
%THRESHOLD PORTION
hold off
planesDiff = 255*(planesDiff>=16);
subplot(4, 1, 4);
imagesc(planesDiff);
axis off
title('THRESHOLD');
4 Comments
Image Analyst
on 23 Sep 2018
Unfortunately it looks like you STILL forgot to attach 'planes1.bmp' and 'planes2.bmp'.
I'll check back tomorrow for the original, single images, not a composite image of 4 images.
Answers (1)
KSSV
on 22 Sep 2018
Edited: KSSV
on 22 Sep 2018
You need not to use find to get the maximum value. max itself gives you the index and value.
[val,idx]=max(I(:));
If you want row and column use ind2sub.
1 Comment
Image Analyst
on 22 Sep 2018
max() only fives the FIRST max, not ALL of the locations. If you want all the locations where the max occurs, you'll still have to use find().
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!