To be honest, thats the exact opposite of what you should be doing. To keep code managable and readable its better to split it up into distinct classes and methods. By throwing everything into a singel method it makes it very hard to track down errors or make changes to parts of the code (as you are finding out now). You woul dbe better to write a class that handles the functionality, pass the image to it and have it return the resulting image. Then inside that class you split up the process into distinct methods.

I'll go over the code in your project and see if i cant hash it together into a more OO friendly structure for you :)

Well frankly, that is what I had done. But as I had mentioned to you, this is for a project and I need to implement each filter as a single class, however complex it maybe. Kinda dumb but cant help it.

DO you mean one class containing all filters, or each filter in a seperate class?

If you have been told to put all of the filters into a single class i would suggest you check with whoever set you the task because either a) there has been some miscommunication and you are approaching this incorrectly or b) they have some very odd views on software development.

This is a clear example of where OO works, each filter is a distinct process so you put it in its own class. Instantiate class, feed in image, get back filtered image.

Are you sure you arent supposed to have a single class which is responsible for loading each filter class and passing the image through them one by one?

I think you have misunderstood me.. Each filter is in a separate class under one project. What I am doing right now has two separate filters, which are in two separate classes. The execute() function calls the other class and performs the reqd operations.

Its more like I have a main form where I can choose what operation I wish to perform. Depending on what I choose, the corresponding filter class is accessed.

In that case you have the right idea :)

Is RegionClassification one of the filter classes? I could see similarities between that and the watershed class but they had different code so i wasnt sure if they were seperate filters or if you had combined several filters into the same method

Ya RegionClassification is one of the filter classes. Like you said, the code is somewhat similar, but both have different functionalities..

aaah, i see. That is what confused me, i assumed you were merging the filters into one which is counterproductive :)
I'll take another look in the light of this fresh perspective ;)

Sure. Meanwhile I am also tryin out some changes. Will let you know if I hit on something

i think region classification needs some attention. It hit errors in a couple of places so you might wanna have a quick scan through and check the logic is sound :)

yeah, u r absolutely right.. That is what i am going through.. in fact im revamping the whole code, analysing it part by part.. will let you know if i encounter something

Hi,

I have revamped the entire code and made a new one. It crossed the previous hurdles, but generates error in the line dstBitmapData = dstImage.LockBits(,...)

But I have not used it previously and I am unlocking it fine.

Can you tell me where the error is .. Or where I am going wrong

Hi, I worked around the problem and got my solution. Thing is it works fine for sometime, but after a point, I get the following error : An unhandled exception of type 'System.OutOfMemoryException' occurred in CytViewStuff1.exe..

i know it is a memory exception and c# doesnt allow you to make necessary changes to avoid this(if im rite)..

But do you have any idea what can be done

Hi,

im not sure how you fixed the bitlock issue, but just for clarity, the Bitmap type is a Class and therefore a reference type. So when you did dstImage = srcImage; you were simply storing a reference to srcImage. So when you tried dstImage.LockBits() you were attempting to lock srcImage, which was already locked.
Use dstImage = (Bitmap)srcImage.Clone(); if you didnt already :)

As for your memory issue, i've noticed you never reset any of your variables. For instance, you create a new list at the start but you dont empty it between images. So you keep adding more and more values to your lists, requiring more and more memory.
I'm not 100% sure, but it could be that thats causing problems. Try re-initialising your variables within your foreach(file in files) loop. Or better yet, any variables that dont need to retain a value between files can be declared inside the loop to ensure they are reset for each file and dont retain useless data.

Hi,

I am just back from my Christmas holidays. Thing is, before i took a vacation, my code seemed to work fine. But now its not working at all. I ve gone thru the entire thing, but am not able to figure out a problem. I am attaching the files here, can you have a look at it?

I know this is one dumb thing that can happen, but I am not able to find the problem

Hi, I worked around and got the solution working. Thanks for all the help so far

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.