I have an image and its centroid and I plotted lines passing through the centroid. And I wonder if it would be possible to represent separately each of the parts that are on either side of the line to work with them separately. You can get to the representation of each of
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
dividing an image into two with the aid of a line
1 回表示 (過去 30 日間)
古いコメントを表示
hello! I have not much experience with matlab and I have a question! I wonder if drawing a line on an image, the image can be divided into two parts from that line and represent each of them separately! thank you very much to all
採用された回答
elena
2013 年 4 月 30 日
15 件のコメント
Image Analyst
2013 年 4 月 30 日
How many lines? What angles are they at? Please upload a screenshot of your image with the line overlaid onto it to snag.gy. And please answer the questions I asked in my comment above.
elena
2013 年 5 月 1 日
the image is melanoma, but it serves any image. I want to draw a line passing through the centroid and I'm spinning at different angles, so the angle is not important. Would be drawing a line on any image, the image can be split through that line. Are not any curved line. What is snag.gy? instead of dividing the image into two parts, I also used two different matrices store the data of each of the parties, but neither is how. Can you help me on this?
Image Analyst
2013 年 5 月 1 日
編集済み: Image Analyst
2013 年 5 月 1 日
An image has to be rectangular. What do you want to have in the space where your quadrilateral image is not present? Just black?
http://snag.gy is a web site where you can just paste your screenshot. Hit print screen, then go to snag.gy and type control-v. Then tell us the URL.
And you never answered my question above as to what it means "to plot" the image. Please answer.
elena
2013 年 5 月 2 日
when I said I meant plot the image to draw or represent the area of the image that was on the side of the line. But now I would have to be able to save the data in a matrix. I mean, I have an image and a line running through it, well, I would like to save on two different data matrices that are on each side of the line, to be able to work well with them separately, not necessarily convert the other values to black. this is my image with a line (which could be any other) http://snag.gy/FyszT.jpg Now I would like to know how to save on two different matrices each of the areas separated by the line. I tried with a for loop but I only keep the last value, not how to save all settings. Do not know if I'm explaining it right. I appreciate your help.
Image Analyst
2013 年 5 月 2 日
Then just scroll up. I didn't sent them to you - I posted them here. Extend your line to the edges of the image, figure out what the coordinates are, then blacken out above or below that, then use imcrop and imwrite for each half.
elena
2013 年 5 月 2 日
I did not understand very well what I have to do. I try to work with the command imcrop, but the only thing I'm able to cut are rectangles, not how to do to crop an image regardless of which direction this the line. Another thing is that to use the command imcrop need not take the points that demarcate the cropped image manually, but I have to do everything programmatically. How I can do? thanks for your help
Image Analyst
2013 年 5 月 2 日
An image must stay rectangular. But you can find the bounding box of your polygon. If you want to analyze within the polygon, then you have to get a binary image of it and use regionprops.
Have you gone through and understood my Image Segmentation Tutorial yet? http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
elena
2013 年 5 月 2 日
I've been watching the demo code for segmentation of the image and I think more or less I understand everything. But I've tried to label the components of my image and I get only one, the whole melanoma, ignores the line to split. So I have not been very clear idea of how to do it. I'm sorry but it is very difficult for me.
Image Analyst
2013 年 5 月 2 日
編集済み: Image Analyst
2013 年 5 月 2 日
Maybe I'll have time later to help you if you upload the original image plus the binary mask that goes with it. No promises though. But what do you want to know about it? The intensity on each side of the line? The length of the line inside the lesion for each angle? Something else?
elena
2013 年 5 月 3 日
I just want to divide it into two parts so to calculate the centroid of each, but I think I know how to do without having to divide them. I try to do, and if I can not resolve I will ask again. Thank you very much for your help.
Image Analyst
2013 年 5 月 3 日
Why do you want the centroid on each side? Well, anyway, here is the code to do that. You will have to change the folder name (where you stored the image because it is not the same folder as where I stored in on my computer), and if you're starting from the original binary image, you can cut out the part where I read in the figure you uploaded and cropped it.
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 = 20;
% Check that user has the Image Processing Toolbox installed.
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
% User does not have the toolbox installed.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end
% Read in a standard MATLAB gray scale demo image.
folder = 'C:\Users\Elena\Documents\Temporary';
baseFileName = 'FyszT.jpg';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
% It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the original gray scale image.
subplot(2, 3, 1);
imshow(grayImage, []);
axis on;
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Give a name to the title bar.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% Crop it
grayImage = imcrop(grayImage, [370, 156, 620, 428]);
subplot(2, 3, 2);
imshow(grayImage, []);
axis on;
title('Cropped Grayscale Image', 'FontSize', fontSize);
% Turn it into a binary image and do a closing to fillin the black line.
binaryImage = imclose(grayImage > 0, true(3));
subplot(2, 3, 3);
imshow(binaryImage, []);
axis on;
title('Binary Image', 'FontSize', fontSize);
% Ask use to draw a line
promptMessage = sprintf('Locate the end points of the line on the upper right image.\nMove to the center of the line (until you get the quad arrows)\nand double click when done');
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'OK', 'Cancel', 'OK');
if strcmpi(button, 'Cancel')
return;
end
hLine = imline;
position = wait(hLine)
% Create a binary image ("mask") from the ROI object.
lineMask = hLine.createMask();
subplot(2, 3, 4);
imshow(lineMask, []);
axis on;
title('Line Mask', 'FontSize', fontSize);
% Burn the line into the image
binaryImage(lineMask) = false;
subplot(2, 3, 5);
imshow(binaryImage, []);
axis on;
title('Binary Object Split into 2 Parts', 'FontSize', fontSize);
labeledImage = bwlabel(binaryImage, 4); % Label each blob so we can make measurements of it
coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle'); % pseudo random color labels
subplot(2, 3, 6);
imagesc(coloredLabels);
axis on;
caption = sprintf('Pseudo colored labels, from label2rgb(),\nwith centroids marked.');
title(caption, 'FontSize', fontSize);
% Get all the blob properties. Can only pass in originalImage in version R2008a and later.
blobMeasurements = regionprops(labeledImage, 'Centroid');
numberOfBlobs = size(blobMeasurements, 1);
hold on;
for blob = 1 : numberOfBlobs
thisCentroid = blobMeasurements(blob).Centroid
plot(thisCentroid(1), thisCentroid(2), 'w+');
end
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/179203/image.jpeg)
elena
2013 年 5 月 4 日
I've managed to do what I was looking for, but anyway I will consider the code you sent me. Thank you very much for all your help, I really appreciate it.
Elysi Cochin
2015 年 5 月 7 日
編集済み: Elysi Cochin
2015 年 5 月 7 日
what if, i have the (x1,y1) and (x2,y2) points... where to edit the code.... how to get the lineMask please do help sir...
Image Analyst
2015 年 5 月 7 日
If you have a large binary blob and you want to burn a line into it, see my attached demo.
その他の回答 (1 件)
Image Analyst
2013 年 4 月 29 日
How do you want to handle it if the line starts and stops within the image? Do you want to extend it until it hits the edge of the image? And then take the bounding box of each quadrilateral and zero out parts on the "wrong" side of the line?
6 件のコメント
elena
2013 年 4 月 30 日
I would like to find a function by which after drawing a line with any angle in the picture, you could plot separately each part of the image that is divided by that line. would this be possible? I appreciate your help
Image Analyst
2013 年 4 月 30 日
So you have two quadrilateral-shaped gray scale images. What does it mean to "plot" them? Some kind of line curve that represents what???
Image Analyst
2013 年 5 月 1 日
編集済み: Image Analyst
2013 年 5 月 1 日
Do you mean like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/179160/image.jpeg)
so that you save two rectangular images, each with a three to five-sided black region?
sameena pathan
2017 年 3 月 21 日
Hello Sir, Kindly help me in resolving this issue. How to divide a segmented portion of an image into two halves with respect to the major axis of the image? Your Kindness is greatly appreciated
Image Analyst
2017 年 4 月 8 日
What information do you have so far? Do you at least have the formula or endpoints of the line? Or do you not even have that? If not, then what do you need to do to get that? Do you need to develop the ENTIRE image segmentation algorithm right from the very start after you call imread()? (I hope not.)
参考
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)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)