understanding the matlab code
Ältere Kommentare anzeigen
There is a code for an image which does filtering. Can anyone help me understand this code? Besides I want to implement this filtering technique for 1D .mat format data having 2 cols and 6000 rows.
14 Kommentare
Rik
am 16 Dez. 2022
If you have rows and columns, your data is not 1D. Also, mat files store variables containing data, but do not technically store the data directly, so a .mat file does not actually contain 2 cols and 6000 rows.
But now to your question. You can easily have a peak at the code. It isn't very long and doesn't contain many variables. The main functionality is in the calls to medfilt2. Have you read the documentation for that function? And have you tried this code with a small example to see if you can predict the output correctly?
bruno
am 16 Dez. 2022
Rik
am 16 Dez. 2022
You didn't actually run this for the image, but for the name of the file containing the image. So you provided a scalar string. I'm surprised you got an output at all and not an error.
An entire image is not actually that small. I was talking about an array of 10x10 at most.
And why do you want to apply this image processing tool to your linear data? What exactly do you want to happen? Perhaps you can write something on your own.
bruno
am 16 Dez. 2022
Rik
am 16 Dez. 2022
You didn't attach a mat file, only a screenshot. I'm not asking these questions to tease you or something. It is very unproductive that you ignore half of what I write. You may have noticed that I try to respond to your entire post and I would ask you to do the same.
I suspect you will be better off processing each lead separately with a 1D moving median. The code you linked to, suggest to me that to implement a relaxed median, you only need two or three calls to movmedian, although you will have to check whether that function was already implemented in R2018a.
Image Analyst
am 17 Dez. 2022
You didn't attach anything. 100.mat is not attached. Is it the one I attached from your other question?
And there may be filters that are especially meant for ecg signals than some generic median filter. Try PubMed
What are you going to do with the signal anyway? I mean, WHY does it need to be filtered? What happens if you just use the original signal? Is there some problem with whatever you're trying to do?
bruno
am 17 Dez. 2022
Rik
am 18 Dez. 2022
Why use a relaxed median filter if you are planning on using an fft later anyway? Wouldn't it be easier to skip that step?
And you still haven't told us how you tried to implement a relaxed median yourself.
bruno
am 18 Dez. 2022
bruno
am 18 Dez. 2022
Walter Roberson
am 18 Dez. 2022
Are you expecting that pictures of the ecg signal will be successfully classified by alexnet? As what, "ball", "tree", "turtle"?? Has alexnet been trained on enough ecg signals to be useful??
bruno
am 18 Dez. 2022
Walter Roberson
am 18 Dez. 2022
When I look around at papers, the ones I find use transfer learning... which requires a dataset of images to train against. Just using the standard pretrained alexnet is not good enough for the papers that I see.
bruno
am 18 Dez. 2022
Antworten (2)
Image Analyst
am 18 Dez. 2022
0 Stimmen
I don't know what "relaxed" median filter is, but you can see how I applied a median filter to images in the attached demos. This is after you've converted your signal to an image.
If you want to filter your 1-D signal before you convert it into an image, then you can use medfilt1, but I'm not sure how you would use that in the whole "relaxed" version of median filter (since I don't know what it is).
Alexnet takes 227x227 RGB images. What features of your spectral image do you plan on measuring? And how do you plan on inserting them into the RGB image?
9 Kommentare
bruno
am 18 Dez. 2022
bruno
am 18 Dez. 2022
That FEX implementation doesn't really look like what the ijetemr.org link describes. That said, the ijetemr.org link has been obviously just pasted from a PDF without proofreading, so the expressions are essentially unreadable. It's hard to say what's being described, but when they say "relax the order statistic", I don't take that to mean "change the window size".
The way I read this mess:
Yi=RM lu {Wi}= {XiifXiE{[Wi](l),[Wi](u)}
{[Wi](m) otherwise
means that for a given sample position, the output pixel is unchanged if it belongs between the lower and upper order statistics of that sample region. If the pixel value lies outside the specified order statistics, then it's replaced with the central order statistic -- the sample median. This could be implemented using ordfilt2() and some comparisons.
Like I said, the FEX implementation doesn't correspond to what the above student paper describes. That said, I don't have institutional access to the parent paper, and I'm not paying for it. This also might just be a totally different interpretation of what a relaxed median filter is.
"By using relaxed median filter, baseline will reduce to zero"
Not as these noise removal filters are described. You'd do that with a simple median filter
detrended = originalsignal - medfilt2(originalsignal,[5 5]);
I'm not sure what the motivation is here. Does the FEX implementation not work? It doesn't seem to work well, but that's kind of what I expected. For better rejection of dense impulse noise that does not extend to the extreme values, an adaptive median noise removal filter does better (at least compared to this one example). Is it just that it needs to be 1D?
bruno
am 18 Dez. 2022
bruno
am 18 Dez. 2022
DGM
am 18 Dez. 2022
If algo.pdf is what you were given to work with, I can see why you're confused. I'm having a hard time figuring out what's even being described. At once it describes using the global median as a filter and then it describes an adaptive filter bound by undescribed criteria.
It asserts that the input is y and then immediately contradicts itself by describing the output as y. It tells you to find the median by sorting the sample, then it tells you to find the median by using median(). It's unclear when it's talking about local and global information, and the expressions it gives confuse both.
Is there any other paperwork that came with this?
bruno
am 18 Dez. 2022
Image Analyst
am 18 Dez. 2022
I agree with DGM in the comment above. The description is very confusing, and it's not only due to it being (obviously) written by a non-native English speaker. It's ambiguous, confusing, contradictory, and basically indecipherable. w is not defined, fs is not defined, m is not defined, Step 2 is gibberish, step 4 seems completely unnecessary, "compared" in Step 6 is not defined, and the criteria in step 8 are not listed.
DGM
am 18 Dez. 2022
Regarding the Hamza paper, without institutional access, I'm not going to spend $40 to find out what exactly they're doing. I trust that the Hamza paper is probably a better reference than the prior student paper or algo.pdf, but that's just an assumption.
Remove the average of 500 samples from each sample obtained by ECG to avoid unwanted noise signals in the entering ECG waveform. The signal’s baseline amplitude is reduced to zero due to this action.
To me, that seems like the baseline reduction is done with a box averaging filter instead of a median filter.
fk = ones(500,1)/500; % a box averaging filter kernel (assuming data is a column vector)
xavg = conv(x,fk,'same'); % local average of 500 samples
y = x-xavg; % remove baseline
The filter is tuned to allow low-frequency impulses while attenuating the high frequencies contained in the erratic ECG signal to minimize the noise of the high-frequency components. The high pass filter allows high frequencies while attenuating low frequencies to minimize low-frequency noise.
I'm not sure what filters you're intended to use for this part or what's canonically appropriate for ECG processing.
denoising is crucial to predict anomalies more accurately. Denoising of the ECG signal is performed using a relaxed median filter.
This is kind of the crux of the matter.
I suppose I could write something based on my vague understanding of what a relaxed median filter is, but I might be wrong in that regard.
I have an unpublished 2D adaptive median filter implementation that probably would work, but I'm pretty sure it's going to be dependent on some other things you might not have.
I'm just going to throw this out there. See the attached file. I don't know if it's correct WRT the Hamza paper, but it seems to be some sort of plausible noise filter. I implemented this as a 2D filter. If you only need 1D, you might be able to use it as-is, but I haven't tested that. I'm just more used to dealing with 2D cases.
inpict0 = imread('cameraman.tif');
inpict = imnoise(inpict0,'salt & pepper',0.1);
outpict = rmedfilt(inpict,5);
imshow(inpict)
imshow(outpict)
I guess it works, but it's not very good. It doesn't take much noise to break it. Compare to an adaptive median filter:

Maybe I'm missing something.
Kategorien
Mehr zu Single-Rate Filters finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

