how can i show only the selected pixels within an image.
2 ビュー (過去 30 日間)
古いコメントを表示
myimage=imread('someimage.jpn') selectedpixels = imcrop(myimage)
filtering "myimage" with the "selectedpixels" to only show this the selected pixels.
0 件のコメント
回答 (1 件)
Naga
2024 年 11 月 26 日
Hi John,
To display only the selected pixels from an image using MATLAB, you can use logical indexing to create a mask of the selected region and then apply this mask to the original image. Here's how you can do it
% Load the image
myimage = imread('anyimage.jpg');
% Select the region of interest (ROI)
[selectedpixels, rect] = imcrop(myimage);
% Create a mask of the same size as the image
mask = false(size(myimage, 1), size(myimage, 2));
x = round(rect(1));
y = round(rect(2));
width = round(rect(3));
height = round(rect(4));
% Set the ROI in the mask to true
mask(y:(y+height), x:(x+width)) = true;
% Apply the mask to the image
filteredimage = myimage;
filteredimage(repmat(~mask, [1 1 size(myimage, 3)])) = 0;
% Display the filtered image
imshow(filteredimage);
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!