how to extract contour using freeman chain code using matlab? [closed] - matlab

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I work in my project on the problem of writer recognition from handwritten Arabic documents.
to identify the writer, I used a database image,
My problem is how to extract features from these images. I'm new in matlab and I do not have much knowledge in image processing.
please help me, I need to extract the contour from image and then encode it using freeman chain codes.
The following link contains freeman code in matlab but I do not know how to use it.
I welcome your suggestion and thank you in advance

You can use the imcontour function.
For instance, if you load this sample image
Img = imread('test.png');
You can get the contour with the command:
C = imcontour(Img, 1);
Then you can use the freeman function you cite with C as the first input.

Another example could be to use bwperim. This essentially takes a look at all of the distinct binary objects in an image and extracts the perimeter of each object. This only works for objects that are white, and so using #Crazy rat's example, we can thus do:
im = ~im2bw(imread('http://i.stack.imgur.com/p9BZl.png'));
out = ~bwperim(im);
The above will read in the image and convert it into binary / logical. Next, we need to invert the image so that the object / text is white while the background is black. After, call bwperim so that you extract the perimeter of the objects, and then to convert back so that the object text is black, we re-invert.
The output I get is:
The distinct advantage with bwperim over imcontour is that bwperim provides the actual output image whereas imcontour only draws a figure for you. You can certainly extract the image data from the figure, like using the h = gcf; out = h.cdata; idiom, but this will include some of the figure background in the result. I suspect you would like the actual raw image instead, and so I would recommend using bwperim.
How do we use this with the Freeman code you linked?
If you look at the source code, it takes in two inputs:
b, which is a N x 2 matrix of coordinates that determine the boundary of the shape you want to encode
unwrap - An optional parameter
If you want to use the function that you have linked us to, simply extract the row and column coordinates of those pixels that are along the boundary of your image. As such, this is another limitation of imcontour, as you won't be able to determine these locations without the raw contour image itself. Therefore, all you really have to do is:
[y,x] = find(out == 0);
cc = chaincode([y x]);

Related

Problem with creating a 3D mask of DICOM-RT contour data using MATLAB

I have troubles extracting a tumor using a RT mask from a dicom image. Due to GDPR I am not allowed to share the dicom images even though they are anonymized. However I am allowed to share the images themself. I want to extract the drawn tumor from the CT images using the draw GTV stored as a RT structure using MATLAB.
Lets say that the file directory where my CT images are stored is called DicomCT and that the RT struct dicom file is called rtStruct.dcm.
I can read and visualize my CT images as follows:
V = dicomreadVolume(“DicomCT”);
V = squeeze(V);
volshow(V)
volume V - 3D CT image
I can load my rt structure using:
Info = dicominfo(“rtStruct.dcm”);
rtContours = dicomContours(Info);
I get the plot giving the different contours.
plotContour(rtContours)
Contours for the GTV of the CT image
I used this link for the information on how to create the mask such that I can apply it to the 3D CT image: https://nl.mathworks.com/help/images/create-and-display-3-d-mask-of-dicom-rt-contour-data.html#d124e5762
The dicom information tells mee the image should be 3mm slices, hence I took 3x3x3 for the referenceInfo.
referenceInfo = imref3d(size(V),3,3,3);
rtMask = createMask(rtContours, 1, referenceInfo)
When I plot my rtMask, I get a grey screen without any trace of the mask. I think that something is wrong with the way that I define the referenceInfo, but I have no idea how to fix it or what is wrong.
volshow(rtMask)
Volume plot of the RT mask
What would be the best way forward?
i was actually having some sort of similar problem to you a couple of days ago. I think you might have two possible problems (none of them your fault).
Your grey screen might be an error rendering that it's not showing because of how the actual volshow() script works. I found it does some things i don't understand with graphics memory and representing numeric type volumes vs logic volumes. I found this the hard way in my job PC where i only have intel HD graphics. Using
iptsetpref('VolumeViewerUseHardware',true)
for logical volumes worked fine for me. You an also test this by trying to replot the mask as double instead of logical by
rtMask = double(rtMask)
volshow(rtMask)
If it's not a rendering error caused by the interactions between your system and volshow() it might be an actual confusion and how the createMask and the actual reference info it needs (created by an actual bad explanation in the tutorial you just linked). Using pixel size info instead of actual axes limits can create partial visualization in segmentation or even missing it bc of scale. This nice person explained more elegantly in this post by using actual geometrical info of the dicom contours as limits.
https://es.mathworks.com/support/search.html/answers/1630195-how-to-convert-dicom-rt-structure-to-binary-mask.html?fq%5B%5D=asset_type_name:answer&fq%5B%5D=category:images/basic-import-and-export&page=1
basically use
plotContour(rtContours);
ax = gca;
referenceInfo = imref3d(size(V),ax.XLim,ax.YLim,ax.ZLim);
rtMask = createMask(rtContours, 1, referenceInfo)
In addition to your code and it might work.
I hope this could be of help to you.

Matlab - Hide a 1MB file in an Image's invaluable bits (Watermarking) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have to store a 1MByte word file into a 512x512 pixels image using Matlab and extract it again. The only thing that I know is that we have to remove the invaluable bits of the image (the ones that are all noise) and store our fie there.
Unfortunately I know nothing about both Matlab and Image Processing.
Thanks All.
Given the numbers provided, you can't. 512x512 give 6.2MBit given 24 bits per pixel. So your doc is larger than the image you are hiding it in.
If we ignore the above, then this is what you have to do:
Load the image and convert to uints.
Mask out a number of LSB bits in each pixel.
Load the doc as binary and fill those bits in where you
masked the others out.
Now, from the above to actual code is a bit of work. If you have no experience with matlab it won't be easy. Try reading up on imread() and bit operations in matlab. When you have some code up and running, then post it here for help.
Regards
In matlab you can read images with imread()
(details on: http://de.mathworks.com/help/matlab/ref/imread.html?s_tid=gn_loc_drop )
Image = imread("Filename.jpg")
figure()
imshow(Image)
This code would show you the Image in a Window.
I think what you're looking for is steganography instead of watermarking.
Steganography:
https://en.wikipedia.org/wiki/Steganography
Here is an example of an image with a file inside it:
http://marvinproject.sourceforge.net/en/plugins/steganography.html
Related topic:
Image Steganography

Color a Point Cloud- Matlab [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a ply image. I want to color it according to my requirement.
1. (.ply) image from kinect
2. Change the rgb value of all point in cloud
e.g
.ply image where all points in the cloud are to be in yellow or blue color.
I have been able to display it using Matlab command "scatter3" but also want to save the colored point cloud as a new point cloud by "pcwrite" function of Matlab.
To answer properly to this question I should know which version of Matlab are you using. If you are using Matlab 2015a you should have these three function
pcread to read a 3D point cloud (.ply file);
pcshow to show a 3D point cloud;
pcwrite to write a .ply file.
Let's say your image is called "airplane.ply".
To properly use that you first read the image using:
ptCloud = pcread('airplane.ply')
then you will notice that ptCloud has different field. One of that regard the color, and is the one you have to change. To do so you have to specify a colour for each point in the cloud. So:
pointscolor=uint8(zeros(ptCloud.Count,3));
pointscolor(:,1)=255;
pointscolor(:,2)=255;
pointscolor(:,3)=51;
since [255 255 51] is the yellow color.
Then assign this matrix to the ptCloud.Color.
ptCloud.Color=pointscolor;
See the result:
pcshow(ptCloud)
and save the file:
pcwrite(ptCloud,'ptCloud.ply')
where 'ptCloud.ply' is the name you want to assign to the file.

How to convert grayscale image to rgb with full colors? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
I'm trying to convert a grayscale image to rgb image . I searched the net and found this code:
rgbImage = repmat(grayImage,[1 1 3]);
rgbImage = cat(3,grayImage,grayImage,grayImage);
but what this does is only give the image in gray-scale with 3-D matrix.
I want to have a way that i can convert it into true color image.
It's impossible to directly recover a colour image from the grey scale version of it. As correctly said by #Luis Mendo in the comments, the needed information are not physically stored there.
What you can do is try to come up with a mapping between intensity level and colour, then play around with interpolation. This however will not produce a good result, but just some colour mapping information that may be very far from what you want.
If you have another colour image and you want to fit its colours to your grey scale image, you may want to have a look at: http://blogs.mathworks.com/pick/2012/11/25/converting-images-from-grayscale-to-color/ .
In particular the function that is there cited can be found here: http://www.mathworks.com/matlabcentral/fileexchange/8214-gray-image-to-color-image-conversion#comments.
Bare in mind that this will be slow and will not produce a great result, however I don't think you can do much more.
yes it's impossible to directly convert gray scale image to rgb..but it is possible to add features or show something like an edge detected on gray scale image in rgb by adding it..if you want you can use this..
rgb = zeros([size(I_temp) 3]);
rgb(:,:,1) = im2double(rr);
rgb(:,:,2) = im2double(rg)+.05*double(I_temp) ;
rgb(:,:,3) = im2double(rb);
where rr,rg,rb are an rgb base image..

Object detection in matlab

I want to write a code in matlab in which i would like to detect color objects in a given image and return the result as found the custom image or not found. i have an image of the custom object separately. im new to matlab... can anyone tell me how to proceed...
i have a pre defined image of an object say an lcd tv.... a given image which may or may not contain the object in it. i need a method to chek and find if the pre defined image is present or not in the given image... is it possible in matlab?
The I suggest you start researching. Stack Overflow is not a great place to ask such generalized questions.
1) Anything that you can do in any programming language is possible in matlab, you are limited by three things:
a) How fast do you want it to work
b) how much coding do you want to do
c) how much of your memory is matlab going to eatup
2) If I am understanding your question correctly you are: Looking to match an image that is fit inside a larger image
Solution: shift your image across the other image, calulate the difference between all the pixels. The set of pixels that is closest to your desired image should be zero.